Fix build-scan-init script to work with build-in build-scan plugins

This commit is contained in:
Daz DeBoer 2021-09-29 14:33:47 -06:00
parent 9b7c81f8f6
commit 60b1ffac6b
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 11 additions and 13 deletions

2
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -18,33 +18,31 @@ import org.gradle.util.GradleVersion
def isTopLevelBuild = gradle.getParent() == null
if (isTopLevelBuild) {
def version = GradleVersion.current().baseVersion
def atLeastGradle5 = version >= GradleVersion.version("5.0")
def atLeastGradle4 = version >= GradleVersion.version("4.0")
def atLeastGradle6 = version >= GradleVersion.version("6.0")
if (atLeastGradle6) {
settingsEvaluated { settings ->
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) {
registerCallbacks(settings.extensions["gradleEnterprise"], settings.rootProject.name)
registerCallbacks(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject.name)
}
}
} else if (atLeastGradle5) {
} else if (atLeastGradle4) {
projectsEvaluated { gradle ->
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) {
registerCallbacks(gradle.rootProject.extensions["gradleEnterprise"], gradle.rootProject.name)
registerCallbacks(gradle.rootProject.extensions["buildScan"], gradle.rootProject.name)
}
}
}
}
def registerCallbacks(gradleEnterprise, rootProjectName) {
gradleEnterprise.with {
buildScan {
def registerCallbacks(buildScanExtension, rootProjectName) {
buildScanExtension.with {
def scanFile = new File("gradle-build-scan.txt")
buildScanPublished { buildScan ->
scanFile.text = buildScan.buildScanUri
}
}
}
}
`
)