Skip to content
This repository was archived by the owner on Aug 19, 2020. It is now read-only.

Commit e497cf5

Browse files
committed
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
1 parent b9cb049 commit e497cf5

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/cache/BuildServices.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object BuildServices {
3333
): ScriptCache {
3434

3535
val hasBuildCacheIntegration =
36-
startParameters.isBuildCacheEnabled && startParameters.isKotlinDslBuildCacheEnabled
36+
startParameters.isBuildCacheEnabled && isKotlinDslBuildCacheEnabled
3737

3838
return ScriptCache(
3939
cacheRepository,
@@ -46,5 +46,5 @@ object BuildServices {
4646

4747

4848
private
49-
val StartParameter.isKotlinDslBuildCacheEnabled: Boolean
50-
get() = projectProperties.getOrDefault("org.gradle.kotlin.dsl.caching.buildcache", null) == "true"
49+
val isKotlinDslBuildCacheEnabled: Boolean
50+
get() = System.getProperty("org.gradle.kotlin.dsl.caching.buildcache", null) == "true"

subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/AbstractScriptCachingIntegrationTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ abstract class AbstractScriptCachingIntegrationTest : AbstractIntegrationTest()
4545

4646
protected
4747
fun buildWithUniqueGradleHome(vararg arguments: String): BuildResult =
48-
buildForCacheInspection("-g", uniqueGradleHome(), *arguments)
48+
buildWithGradleHome(uniqueGradleHome(), *arguments)
49+
50+
protected
51+
fun buildWithGradleHome(gradleHomePath: String, vararg arguments: String) =
52+
buildForCacheInspection("-g", gradleHomePath, *arguments)
53+
54+
protected
55+
fun <T> withUniqueGradleHome(f: (String) -> T): T =
56+
f(uniqueGradleHome())
4957

5058
private
5159
fun uniqueGradleHome() =

subprojects/provider/src/test/kotlin/org/gradle/kotlin/dsl/caching/BuildCacheIntegrationTest.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() {
5959

6060
@LeaksFileHandles("on the separate Gradle homes")
6161
@Test
62-
fun `build cache integration is enabled via project property`() {
62+
fun `build cache integration is enabled via system property`() {
6363

6464
val buildCacheDir =
6565
existing("build-cache")
@@ -91,15 +91,22 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() {
9191
assertThat(output, containsString(expectedOutput))
9292
}
9393

94-
// Cache hit from build cache
95-
buildWithUniqueGradleHome("--build-cache", withBuildCacheIntegration).apply {
94+
// Cache hit from build cache (enabled via gradle.properties file)
95+
withUniqueGradleHome { gradleHome ->
9696

97-
compilationCache {
98-
misses(cachedSettingsFile)
99-
hits(cachedBuildFile)
100-
}
97+
File(gradleHome, "gradle.properties").writeText(
98+
"systemProp.$kotlinDslBuildCacheEnabled"
99+
)
101100

102-
assertThat(output, containsString(expectedOutput))
101+
buildWithGradleHome(gradleHome, "--build-cache").apply {
102+
103+
compilationCache {
104+
misses(cachedSettingsFile)
105+
hits(cachedBuildFile)
106+
}
107+
108+
assertThat(output, containsString(expectedOutput))
109+
}
103110
}
104111

105112
// Cache miss without build cache integration
@@ -115,7 +122,10 @@ class BuildCacheIntegrationTest : AbstractScriptCachingIntegrationTest() {
115122
}
116123

117124
private
118-
val withBuildCacheIntegration = "-Porg.gradle.kotlin.dsl.caching.buildcache=true"
125+
val kotlinDslBuildCacheEnabled = "org.gradle.kotlin.dsl.caching.buildcache=true"
126+
127+
private
128+
val withBuildCacheIntegration = "-D$kotlinDslBuildCacheEnabled"
119129

120130
private
121131
fun withLocalBuildCacheSettings(buildCacheDir: File): File =

0 commit comments

Comments
 (0)