Skip to content

Commit ef01947

Browse files
Merge pull request #365 from gradle/erichaagdev/null-sys-props-v2
Experiments can be run with `-XX` arguments and the configuration cache is not invalidated between runs
2 parents 71e6db1 + fddc75f commit ef01947

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Diff for: components/scripts/gradle/gradle-init-scripts/configure-gradle-enterprise.gradle

+19-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ initscript {
1010
return
1111
}
1212

13+
// the way this closure reads system properties means they are not tracked as inputs to the configuration cache model,
14+
// the same is the case when reading environment variables with Gradle [6.5, 7.3]
1315
def getInputParam = { String name ->
1416
def envVarName = name.toUpperCase().replace('.', '_').replace('-', '_')
15-
return System.getProperty(name) ?: System.getenv(envVarName)
17+
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getenv(envVarName)
1618
}
1719

20+
// the following local variables do not change between the build invocations of the same experiment run
21+
// thus, reading their values in way that the configuration cache does not track them is acceptable
1822
def pluginRepositoryUrl = getInputParam('com.gradle.enterprise.build-validation.gradle.plugin-repository.url')
1923
def gePluginVersion = getInputParam('com.gradle.enterprise.build-validation.gradle-enterprise.plugin.version')
2024
def ccudPluginVersion = getInputParam('com.gradle.enterprise.build-validation.ccud.plugin.version')
@@ -59,11 +63,15 @@ if (!isTopLevelBuild) {
5963
return
6064
}
6165

66+
// the way this closure reads system properties means they are not tracked as inputs to the configuration cache model,
67+
// the same is the case when reading environment variables with Gradle [6.5, 7.3]
6268
def getInputParam = { String name ->
6369
def envVarName = name.toUpperCase().replace('.', '_').replace('-', '_')
64-
return System.getProperty(name) ?: System.getenv(envVarName)
70+
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getenv(envVarName)
6571
}
6672

73+
// the following local variables do not change between the build invocations of the same experiment run
74+
// thus, reading their values in way that the configuration cache does not track them is acceptable
6775
def geUrl = getInputParam('com.gradle.enterprise.build-validation.gradle-enterprise.url')
6876
def geAllowUntrustedServer = Boolean.parseBoolean(getInputParam('com.gradle.enterprise.build-validation.gradle-enterprise.allow-untrusted-server'))
6977
def gePluginVersion = getInputParam('com.gradle.enterprise.build-validation.gradle-enterprise.plugin.version')
@@ -72,7 +80,6 @@ def ccudPluginVersion = getInputParam('com.gradle.enterprise.build-validation.cc
7280
def expDir = getInputParam('com.gradle.enterprise.build-validation.expDir')
7381
def expId = getInputParam('com.gradle.enterprise.build-validation.expId')
7482
def runId = getInputParam('com.gradle.enterprise.build-validation.runId')
75-
def runNum = getInputParam('com.gradle.enterprise.build-validation.runNum')
7683
def scriptsVersion = getInputParam('com.gradle.enterprise.build-validation.scriptsVersion')
7784

7885
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@@ -87,6 +94,15 @@ if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
8794
def registerBuildScanActions = { def buildScan ->
8895
def scanFile = new File(expDir, 'build-scans.csv')
8996
buildScan.buildScanPublished { publishedBuildScan ->
97+
// defer reading the `runNum` system property until execution time since it does not affect
98+
// the configuration of the build, and given its value changes between consecutive build invocations
99+
// it would always invalidate the configuration cache model from the first build invocation
100+
// in the second build invocation
101+
def getRunNumInputParam = { String name ->
102+
def envVarName = name.toUpperCase().replace('.', '_').replace('-', '_')
103+
return System.getProperty(name) ?: System.getenv(envVarName)
104+
}
105+
def runNum = getRunNumInputParam('com.gradle.enterprise.build-validation.runNum')
90106
def buildScanUri = publishedBuildScan.buildScanUri
91107
def buildScanId = publishedBuildScan.buildScanId
92108
def port = (buildScanUri.port != -1) ? ':' + buildScanUri.port : ''

Diff for: components/scripts/gradle/gradle-init-scripts/configure-local-build-caching.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ if (!isTopLevelBuild) {
33
return
44
}
55

6+
// the way this closure reads system properties means they are not tracked as inputs to the configuration cache model,
7+
// the same is the case when reading environment variables with Gradle [6.5, 7.3]
68
def getInputParam = { String name ->
79
def envVarName = name.toUpperCase().replace('.', '_').replace('-', '_')
8-
return System.getProperty(name) ?: System.getenv(envVarName)
10+
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getenv(envVarName)
911
}
1012

13+
// the following local variable does not change between the build invocations of the same experiment run
14+
// thus, reading its value in way that the configuration cache does not track it is acceptable
1115
def expDir = getInputParam('com.gradle.enterprise.build-validation.expDir')
1216

1317
settingsEvaluated { settings ->

Diff for: components/scripts/gradle/gradle-init-scripts/configure-remote-build-caching.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ if (!isTopLevelBuild) {
33
return
44
}
55

6+
// the way this closure reads system properties means they are not tracked as inputs to the configuration cache model,
7+
// the same is the case when reading environment variables with Gradle [6.5, 7.3]
68
def getInputParam = { String name ->
79
def envVarName = name.toUpperCase().replace('.', '_').replace('-', '_')
8-
return System.getProperty(name) ?: System.getenv(envVarName)
10+
return gradle.startParameter.systemPropertiesArgs[name] ?: System.getenv(envVarName)
911
}
1012

13+
// the following local variable does not change between the build invocations of the same experiment run
14+
// thus, reading its value in way that the configuration cache does not track it is acceptable
1115
def remoteBuildCacheUrl = getInputParam('com.gradle.enterprise.build-validation.remoteBuildCacheUrl')
1216

1317
settingsEvaluated { settings ->

0 commit comments

Comments
 (0)