Adapt build-result-capture script for GE plugin 3.17+
Some checks failed
CI-ossf-scorecard / Scorecard analysis (push) Has been cancelled
CI-update-dist / update-dist (push) Has been cancelled
CI-validate-wrappers / validation (push) Has been cancelled
CI-check-and-unit-test / check-format-and-unit-test (push) Has been cancelled
CI-codeql / Analyze (push) Has been cancelled
CI-init-script-check / test-init-scripts (push) Has been cancelled
CI-integ-test / build-distribution (push) Has been cancelled
CI-integ-test / caching-integ-tests (push) Has been cancelled
CI-integ-test / other-integ-tests (push) Has been cancelled

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
This commit is contained in:
daz 2024-11-16 15:48:08 -07:00 committed by Daz DeBoer
parent d85b0068a7
commit e55599fc4d

View file

@ -32,15 +32,19 @@ if (isTopLevelBuild) {
// Use the Develocity plugin to also capture build scan links, when available // Use the Develocity plugin to also capture build scan links, when available
settingsEvaluated { settings -> settingsEvaluated { settings ->
settings.pluginManager.withPlugin(GE_PLUGIN_ID) { def captureBuildScanLink = {
// Only execute if develocity plugin isn't applied. // Prefer the 'develocity' extension, if available
if (!settings.extensions.findByName(DEVELOCITY_EXTENSION)) { if (settings.extensions.findByName(DEVELOCITY_EXTENSION)) {
captureUsingBuildScanPublished(settings.extensions[DEVELOCITY_EXTENSION].buildScan, invocationId, resultsWriter)
} else {
captureUsingBuildScanPublished(settings.extensions[GE_EXTENSION].buildScan, invocationId, resultsWriter) captureUsingBuildScanPublished(settings.extensions[GE_EXTENSION].buildScan, invocationId, resultsWriter)
} }
} }
settings.pluginManager.withPlugin(GE_PLUGIN_ID, captureBuildScanLink)
settings.pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) { 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) { } else if (atLeastGradle3) {
@ -48,15 +52,21 @@ if (isTopLevelBuild) {
// By default, use 'buildFinished' to capture build results // By default, use 'buildFinished' to capture build results
captureUsingBuildFinished(gradle, invocationId, resultsWriter) captureUsingBuildFinished(gradle, invocationId, resultsWriter)
gradle.rootProject.pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) { def captureBuildScanLink = {
// Only execute if develocity plugin isn't applied. // Prefer the 'develocity' extension, if available
if (!gradle.rootProject.extensions.findByName(DEVELOCITY_EXTENSION)) { 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) 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) { 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()
} }
} }
} }