Use settingsEvaluated in preference to projectsEvaluated in init-script

This commit is contained in:
daz 2024-07-18 13:38:19 -06:00
parent b7e399239c
commit 6d20c16462
No known key found for this signature in database
2 changed files with 12 additions and 14 deletions

View file

@ -2,12 +2,10 @@ import org.gradle.tooling.events.*
import org.gradle.tooling.events.task.*
import org.gradle.util.GradleVersion
// Can't use settingsEvaluated since this script is applied inside a settingsEvaluated handler
// But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway
projectsEvaluated {
settingsEvaluated { settings ->
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-action-buildResultsRecorder", BuildResultsRecorder, { spec ->
spec.getParameters().getRootProjectName().set(gradle.rootProject.name)
spec.getParameters().getRootProjectDir().set(gradle.rootProject.rootDir.absolutePath)
spec.getParameters().getRootProjectName().set(settings.rootProject.name)
spec.getParameters().getRootProjectDir().set(settings.rootDir.absolutePath)
spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" "))
spec.getParameters().getGradleHomeDir().set(gradle.gradleHomeDir.absolutePath)
spec.getParameters().getInvocationId().set(gradle.ext.invocationId)

View file

@ -21,16 +21,16 @@ if (isTopLevelBuild) {
def invocationId = "-${System.currentTimeMillis()}"
if (atLeastGradle6) {
// By default, use standard mechanisms to capture build results
def useBuildService = version >= GradleVersion.version("6.6")
if (useBuildService) {
captureUsingBuildService(invocationId)
} else {
captureUsingBuildFinished(gradle, invocationId)
}
// Use the Develocity plugin to also capture build scan links, when available
settingsEvaluated { settings ->
// By default, use standard mechanisms to capture build results
if (useBuildService) {
captureUsingBuildService(settings, invocationId)
} else {
captureUsingBuildFinished(gradle, invocationId)
}
settings.pluginManager.withPlugin(GE_PLUGIN_ID) {
// Only execute if develocity plugin isn't applied.
if (!settings.extensions.findByName(DEVELOCITY_EXTENSION)) {
@ -100,7 +100,7 @@ def captureUsingBuildFinished(gradle, invocationId) {
}
}
def captureUsingBuildService(settings, invocationId) {
def captureUsingBuildService(invocationId) {
gradle.ext.invocationId = invocationId
apply from: 'gradle-actions.build-result-capture-service.plugin.groovy'
}