Skip to content

Commit

Permalink
Adapt build-result-capture script for GE plugin 3.17+
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bigdaz committed Nov 17, 2024
1 parent d85b006 commit e55599f
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,41 @@ 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) {
projectsEvaluated { gradle ->
// 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()
}
}
}
Expand Down

0 comments on commit e55599f

Please sign in to comment.