Use a BuildService to always collect project root

Using `settingsEvaluated` meant that the project root was not recorded
when the build was run with a config-cache hit. This meant that the subsequent
build would not restore the config-cache, resulting in a cache miss.

In order to avoid issues running the init script on older versions of Gradle
the project-collection is extracted into a separate groovy file that is only
applied conditionally on Gradle 7 or higher.
This commit is contained in:
Daz DeBoer 2022-06-03 10:45:51 -06:00
parent cde0632795
commit ae74c01440
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
4 changed files with 58 additions and 12 deletions

View file

@ -170,7 +170,11 @@ export class GradleStateCache {
const propertiesFile = path.resolve(gradleUserHome, 'gradle.properties')
fs.appendFileSync(propertiesFile, 'org.gradle.daemon=false')
const initScriptFilenames = ['build-result-capture.init.gradle', 'project-root-capture.init.gradle']
const initScriptFilenames = [
'build-result-capture.init.gradle',
'project-root-capture.init.gradle',
'project-root-capture.plugin.groovy'
]
for (const initScriptFilename of initScriptFilenames) {
const initScriptContent = this.readResourceAsString(initScriptFilename)
const initScriptPath = path.resolve(initScriptsDir, initScriptFilename)