From e55599fc4d8b81ced2a6234b0b2525b1031e93fa Mon Sep 17 00:00:00 2001 From: daz Date: Sat, 16 Nov 2024 15:48:08 -0700 Subject: [PATCH] Adapt build-result-capture script for GE plugin 3.17+ The build-result-capture.init.gradle script was making some assumptions about extensions and plugin application that do not apply with the newest GE plugin. Fixes #449 --- ...e-actions.build-result-capture.init.gradle | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) 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 9f66309..120691b 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 @@ -32,15 +32,19 @@ if (isTopLevelBuild) { // Use the Develocity plugin to also capture build scan links, when available settingsEvaluated { settings -> - settings.pluginManager.withPlugin(GE_PLUGIN_ID) { - // Only execute if develocity plugin isn't applied. - if (!settings.extensions.findByName(DEVELOCITY_EXTENSION)) { + def captureBuildScanLink = { + // Prefer the 'develocity' extension, if available + if (settings.extensions.findByName(DEVELOCITY_EXTENSION)) { + captureUsingBuildScanPublished(settings.extensions[DEVELOCITY_EXTENSION].buildScan, invocationId, resultsWriter) + } else { captureUsingBuildScanPublished(settings.extensions[GE_EXTENSION].buildScan, invocationId, resultsWriter) } } - + settings.pluginManager.withPlugin(GE_PLUGIN_ID, captureBuildScanLink) settings.pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) { - captureUsingBuildScanPublished(settings.extensions[DEVELOCITY_EXTENSION].buildScan, invocationId, resultsWriter) + // Develocity plugin applies GE plugin: avoid duplicate call + if (settings.pluginManager.hasPlugin(GE_PLUGIN_ID)) return + captureBuildScanLink() } } } else if (atLeastGradle3) { @@ -48,15 +52,21 @@ if (isTopLevelBuild) { // By default, use 'buildFinished' to capture build results captureUsingBuildFinished(gradle, invocationId, resultsWriter) - gradle.rootProject.pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) { - // Only execute if develocity plugin isn't applied. - if (!gradle.rootProject.extensions.findByName(DEVELOCITY_EXTENSION)) { + def captureBuildScanLink = { + // Prefer the 'develocity' extension, if available + if (gradle.rootProject.extensions.findByName(DEVELOCITY_EXTENSION)) { + captureUsingBuildScanPublished(gradle.rootProject.extensions[DEVELOCITY_EXTENSION].buildScan, invocationId, resultsWriter) + } else { captureUsingBuildScanPublished(gradle.rootProject.extensions[BUILD_SCAN_EXTENSION], invocationId, resultsWriter) } } + gradle.rootProject.pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID, captureBuildScanLink) + gradle.rootProject.pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) { - captureUsingBuildScanPublished(gradle.rootProject.extensions[DEVELOCITY_EXTENSION].buildScan, invocationId, resultsWriter) + // Develocity plugin applies Build Scan plugin: avoid duplicate call + if (gradle.rootProject.pluginManager.hasPlugin(BUILD_SCAN_PLUGIN_ID)) return + captureBuildScanLink() } } }