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 72a5c4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
'compileSdk': 27,

'supportLibrary': '27.0.2',
'androidPlugin': '3.1.0-alpha09',
'androidPlugin': '3.1.2',
'androidTools': '26.1.0-alpha09',
'kotlin': '1.2.21',

Expand Down
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 72a5c4c

Please sign in to comment.