Skip to content

Commit

Permalink
Fix configuration-cache compatibility
Browse files Browse the repository at this point in the history
Configuration-cache won't actually re-register extensions,
so resolving it at task execution time actually fails.
This is worked around by not resolving the extension from
the ExtensionContainer at execution time, but referencing
the extension that's already in-scope in the code.

Fixes #59
  • Loading branch information
tbroyer committed Jun 27, 2021
1 parent b095f6e commit bb2c9c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,20 @@ Add a dependency to com.google.errorprone:javac with the appropriate version cor
inputs.files(
providers.provider {
when {
!options.errorprone.isEnabled.getOrElse(false) -> emptyList()
HAS_TOOLCHAINS && javaCompiler.isPresent -> {
!errorproneOptions.isEnabled.getOrElse(false) -> emptyList()
HAS_TOOLCHAINS && javaCompiler.isPresent ->
when (javaCompiler.get().metadata.languageVersion.asInt()) {
8 -> javacConfiguration
else -> emptyList()
}
}
JavaVersion.current().isJava8 -> javacConfiguration
else -> emptyList()
}
}
).withPropertyName(JAVAC_CONFIGURATION_NAME).withNormalizer(ClasspathNormalizer::class)
doFirst("configure errorprone in bootclasspath") {
when {
!options.errorprone.isEnabled.getOrElse(false) -> return@doFirst
!errorproneOptions.isEnabled.getOrElse(false) -> return@doFirst
HAS_TOOLCHAINS && javaCompiler.isPresent -> {
val targetVersion = javaCompiler.get().metadata.languageVersion.asInt()
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,29 @@ class ErrorPronePluginIntegrationTest : AbstractPluginIntegrationTest() {
).isFalse()

// given
writeSuccessSource()
// Use a failing check to make sure that the configuration is properly persisted/reloaded
buildFile.appendText(
"""
tasks.withType<JavaCompile>().configureEach {
options.errorprone {
disable("ArrayEquals")
}
}
""".trimIndent()
)
writeFailureSource()

// Prime the configuration cache
buildWithArgs("--configuration-cache", "compileJava")

// when
val result = buildWithArgs("--configuration-cache", "compileJava")
val result = buildWithArgs("--configuration-cache", "--rerun-tasks", "--debug", "compileJava")

// then
assertThat(result.output).contains("Reusing configuration cache.")
// Check that the second run indeed used ErrorProne.
// As it didn't fail, it means the rest of the configuration was properly persisted/reloaded.
assertThat(result.output).contains("-Xplugin:ErrorProne")
}
}

0 comments on commit bb2c9c7

Please sign in to comment.