From 6d20c164627f89d66d96f4330e072f78b60c2750 Mon Sep 17 00:00:00 2001 From: daz Date: Thu, 18 Jul 2024 13:38:19 -0600 Subject: [PATCH] Use `settingsEvaluated` in preference to `projectsEvaluated` in init-script --- ....build-result-capture-service.plugin.groovy | 8 +++----- ...le-actions.build-result-capture.init.gradle | 18 +++++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy b/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy index e1adda6..6ea2c5a 100644 --- a/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy +++ b/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy @@ -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) diff --git a/sources/src/resources/init-scripts/gradle-actions.build-result-capture.init.gradle b/sources/src/resources/init-scripts/gradle-actions.build-result-capture.init.gradle index 160afe4..5cfca2a 100644 --- a/sources/src/resources/init-scripts/gradle-actions.build-result-capture.init.gradle +++ b/sources/src/resources/init-scripts/gradle-actions.build-result-capture.init.gradle @@ -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' }