mirror of
https://github.com/gradle/actions.git
synced 2026-03-24 04:55:48 +08:00
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:
@@ -1,12 +1,10 @@
|
||||
// Capture the build root directory for each executed Gradle build.
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
// Only run against root build. Do not run against included builds.
|
||||
def isTopLevelBuild = gradle.getParent() == null
|
||||
if (isTopLevelBuild) {
|
||||
settingsEvaluated { settings ->
|
||||
def projectRootEntry = settings.rootDir.absolutePath + '\n'
|
||||
def projectRootList = new File(settings.gradle.gradleUserHomeDir, "project-roots.txt")
|
||||
if (!projectRootList.exists() || !projectRootList.text.contains(projectRootEntry)) {
|
||||
projectRootList << projectRootEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only record configuration-cache entries for Gradle 7+
|
||||
def isAtLeastGradle7 = GradleVersion.current() >= GradleVersion.version('7.0')
|
||||
|
||||
if (isTopLevelBuild && isAtLeastGradle7) {
|
||||
apply from: 'project-root-capture.plugin.groovy'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user