From e497cf5bcf236c5430d4a108397bb608a71190b0 Mon Sep 17 00:00:00 2001 From: "Rodrigo B. de Oliveira" Date: Mon, 13 Aug 2018 10:41:19 -0300 Subject: [PATCH] Let build cache integration be enabled via system property instead of project property And prove it can be enabled via `$GRADLE_HOME/gradle.properties`. See #1032 --- .../gradle/kotlin/dsl/cache/BuildServices.kt | 6 ++-- .../AbstractScriptCachingIntegrationTest.kt | 10 ++++++- .../dsl/caching/BuildCacheIntegrationTest.kt | 28 +++++++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/cache/BuildServices.kt b/subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/cache/BuildServices.kt index 8b1064d9a..547b45aae 100644 --- a/subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/cache/BuildServices.kt +++ b/subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/cache/BuildServices.kt @@ -33,7 +33,7 @@ object BuildServices { ): ScriptCache { val hasBuildCacheIntegration = - startParameters.isBuildCacheEnabled && startParameters.isKotlinDslBuildCacheEnabled + startParameters.isBuildCacheEnabled && isKotlinDslBuildCacheEnabled return ScriptCache( cacheRepository, @@ -46,5 +46,5 @@ object BuildServices { private -val StartParameter.isKotlinDslBuildCacheEnabled: Boolean - get() = projectProperties.getOrDefault("org.gradle.kotlin.dsl.caching.buildcache", null) == "true" +val isKotlinDslBuildCacheEnabled: Boolean + get() = System.getProperty("org.gradle.kotlin.dsl.caching.buildcache", null) == "true" diff --git a/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/AbstractScriptCachingIntegrationTest.kt b/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/AbstractScriptCachingIntegrationTest.kt index 385341d9d..63688a538 100644 --- a/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/AbstractScriptCachingIntegrationTest.kt +++ b/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/AbstractScriptCachingIntegrationTest.kt @@ -45,7 +45,15 @@ abstract class AbstractScriptCachingIntegrationTest : AbstractIntegrationTest() protected fun buildWithUniqueGradleHome(vararg arguments: String): BuildResult = - buildForCacheInspection("-g", uniqueGradleHome(), *arguments) + buildWithGradleHome(uniqueGradleHome(), *arguments) + + protected + fun buildWithGradleHome(gradleHomePath: String, vararg arguments: String) = + buildForCacheInspection("-g", gradleHomePath, *arguments) + + protected + fun withUniqueGradleHome(f: (String) -> T): T = + f(uniqueGradleHome()) private fun uniqueGradleHome() = diff --git a/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/BuildCacheIntegrationTest.kt b/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/BuildCacheIntegrationTest.kt index 2e363af2a..d710b8465 100644 --- a/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/BuildCacheIntegrationTest.kt +++ b/subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/BuildCacheIntegrationTest.kt @@ -59,7 +59,7 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() { @LeaksFileHandles("on the separate Gradle homes") @Test - fun `build cache integration is enabled via project property`() { + fun `build cache integration is enabled via system property`() { val buildCacheDir = existing("build-cache") @@ -91,15 +91,22 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() { assertThat(output, containsString(expectedOutput)) } - // Cache hit from build cache - buildWithUniqueGradleHome("--build-cache", withBuildCacheIntegration).apply { + // Cache hit from build cache (enabled via gradle.properties file) + withUniqueGradleHome { gradleHome -> - compilationCache { - misses(cachedSettingsFile) - hits(cachedBuildFile) - } + File(gradleHome, "gradle.properties").writeText( + "systemProp.$kotlinDslBuildCacheEnabled" + ) - assertThat(output, containsString(expectedOutput)) + buildWithGradleHome(gradleHome, "--build-cache").apply { + + compilationCache { + misses(cachedSettingsFile) + hits(cachedBuildFile) + } + + assertThat(output, containsString(expectedOutput)) + } } // Cache miss without build cache integration @@ -115,7 +122,10 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() { } private - val withBuildCacheIntegration = "-Porg.gradle.kotlin.dsl.caching.buildcache=true" + val kotlinDslBuildCacheEnabled = "org.gradle.kotlin.dsl.caching.buildcache=true" + + private + val withBuildCacheIntegration = "-D$kotlinDslBuildCacheEnabled" private fun withLocalBuildCacheSettings(buildCacheDir: File): File =