Skip to content

Commit

Permalink
Enable task caching for R2Generator.
Browse files Browse the repository at this point in the history
This enables gradle task caching for the R2 Generating task.

Some more info on task caching:
https://github.com/gradle/task-output-cache-demos/blob/master/docs/making-custom-tasks-cacheable.md
  • Loading branch information
Nelson Osacky committed Jun 20, 2018
1 parent f0b7351 commit 3470097
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.DomainObjectSet
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.tasks.PathSensitivity
import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass
Expand Down Expand Up @@ -58,7 +59,7 @@ class ButterKnifePlugin : Plugin<Project> {
"generated/source/r2/${variant.dirName}")

val task = project.tasks.create("generate${variant.name.capitalize()}R2")
task.outputs.dir(outputDir)
task.outputs.dir(outputDir).withPropertyName("output").cacheIf { true }
variant.registerJavaGeneratingTask(task, outputDir)

val rPackage = getPackageName(variant)
Expand All @@ -74,7 +75,7 @@ class ButterKnifePlugin : Plugin<Project> {
val rFile = processResources.sourceOutputDir.resolve(pathToR).resolve("R.java")

task.apply {
inputs.file(rFile)
inputs.file(rFile).withPathSensitivity(PathSensitivity.RELATIVE)

doLast {
FinalRClassBuilder.brewJava(rFile, outputDir, rPackage, "R2")
Expand All @@ -86,6 +87,6 @@ class ButterKnifePlugin : Plugin<Project> {
}

private operator fun <T : Any> ExtensionContainer.get(type: KClass<T>): T {
return getByType(type.java)!!
return getByType(type.java)
}
}

0 comments on commit 3470097

Please sign in to comment.