mirror of
https://github.com/gradle/actions.git
synced 2025-04-23 03:09:20 +08:00
Update develocity-injection init script to v0.5.0
This commit is contained in:
parent
edb13383f3
commit
e6103d397b
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Initscript for injection of Develocity into Gradle builds.
|
* Initscript for injection of Develocity into Gradle builds.
|
||||||
* Version: v0.4.0
|
* Version: v0.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
@ -14,8 +14,8 @@ initscript {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
def ENV_VAR_PREFIX = ''
|
|
||||||
def getInputParam = { String name ->
|
def getInputParam = { String name ->
|
||||||
|
def ENV_VAR_PREFIX = ''
|
||||||
def envVarName = ENV_VAR_PREFIX + name.toUpperCase().replace('.', '_').replace('-', '_')
|
def envVarName = ENV_VAR_PREFIX + name.toUpperCase().replace('.', '_').replace('-', '_')
|
||||||
return System.getProperty(name) ?: System.getenv(envVarName)
|
return System.getProperty(name) ?: System.getenv(envVarName)
|
||||||
}
|
}
|
||||||
@ -26,9 +26,9 @@ initscript {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish early if injection is disabled
|
// plugin loading is only required for Develocity injection
|
||||||
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
|
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam("develocity.injection-enabled"))
|
||||||
if (gradleInjectionEnabled != "true") {
|
if (!develocityInjectionEnabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,30 +81,17 @@ initscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'
|
static getInputParam(String name) {
|
||||||
def BUILD_SCAN_PLUGIN_CLASS = 'com.gradle.scan.plugin.BuildScanPlugin'
|
def ENV_VAR_PREFIX = ''
|
||||||
|
def envVarName = ENV_VAR_PREFIX + name.toUpperCase().replace('.', '_').replace('-', '_')
|
||||||
def GRADLE_ENTERPRISE_PLUGIN_ID = 'com.gradle.enterprise'
|
return System.getProperty(name) ?: System.getenv(envVarName)
|
||||||
def GRADLE_ENTERPRISE_PLUGIN_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin'
|
}
|
||||||
|
|
||||||
def DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
|
|
||||||
def DEVELOCITY_PLUGIN_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityPlugin'
|
|
||||||
|
|
||||||
def CI_AUTO_INJECTION_CUSTOM_VALUE_NAME = 'CI auto injection'
|
|
||||||
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
|
|
||||||
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
|
|
||||||
|
|
||||||
def isTopLevelBuild = !gradle.parent
|
def isTopLevelBuild = !gradle.parent
|
||||||
if (!isTopLevelBuild) {
|
if (!isTopLevelBuild) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
def ENV_VAR_PREFIX = ''
|
|
||||||
def getInputParam = { String name ->
|
|
||||||
def envVarName = ENV_VAR_PREFIX + name.toUpperCase().replace('.', '_').replace('-', '_')
|
|
||||||
return System.getProperty(name) ?: System.getenv(envVarName)
|
|
||||||
}
|
|
||||||
|
|
||||||
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
|
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
|
||||||
def initScriptName = buildscript.sourceFile.name
|
def initScriptName = buildscript.sourceFile.name
|
||||||
if (requestedInitScriptName != initScriptName) {
|
if (requestedInitScriptName != initScriptName) {
|
||||||
@ -112,205 +99,226 @@ if (requestedInitScriptName != initScriptName) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish early if injection is disabled
|
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam("develocity.injection-enabled"))
|
||||||
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
|
if (develocityInjectionEnabled) {
|
||||||
if (gradleInjectionEnabled != "true") {
|
enableDevelocityInjection()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def develocityUrl = getInputParam('develocity.url')
|
// To enable build-scan capture, a `captureBuildScanLink(String)` method must be added to `BuildScanCollector`.
|
||||||
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam('develocity.allow-untrusted-server'))
|
def buildScanCollector = new BuildScanCollector()
|
||||||
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url'))
|
def buildScanCaptureEnabled = buildScanCollector.metaClass.respondsTo(buildScanCollector, 'captureBuildScanLink', String)
|
||||||
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam('develocity.build-scan.upload-in-background'))
|
if (buildScanCaptureEnabled) {
|
||||||
def develocityCaptureFileFingerprints = getInputParam('develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints')) : true
|
enableBuildScanLinkCapture(buildScanCollector)
|
||||||
def develocityPluginVersion = getInputParam('develocity.plugin.version')
|
}
|
||||||
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
|
|
||||||
def buildScanTermsOfUseUrl = getInputParam('develocity.terms-of-use.url')
|
|
||||||
def buildScanTermsOfUseAgree = getInputParam('develocity.terms-of-use.agree')
|
|
||||||
def ciAutoInjectionCustomValueValue = getInputParam('develocity.auto-injection.custom-value')
|
|
||||||
|
|
||||||
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
void enableDevelocityInjection() {
|
||||||
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
def BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'
|
||||||
def shouldApplyDevelocityPlugin = atLeastGradle5 && develocityPluginVersion && isAtLeast(develocityPluginVersion, '3.17')
|
def BUILD_SCAN_PLUGIN_CLASS = 'com.gradle.scan.plugin.BuildScanPlugin'
|
||||||
|
|
||||||
def dvOrGe = { def dvValue, def geValue ->
|
def GRADLE_ENTERPRISE_PLUGIN_ID = 'com.gradle.enterprise'
|
||||||
if (shouldApplyDevelocityPlugin) {
|
def GRADLE_ENTERPRISE_PLUGIN_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin'
|
||||||
return dvValue instanceof Closure<?> ? dvValue() : dvValue
|
|
||||||
|
def DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
|
||||||
|
def DEVELOCITY_PLUGIN_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityPlugin'
|
||||||
|
|
||||||
|
def CI_AUTO_INJECTION_CUSTOM_VALUE_NAME = 'CI auto injection'
|
||||||
|
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
|
||||||
|
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
|
||||||
|
|
||||||
|
def develocityUrl = getInputParam('develocity.url')
|
||||||
|
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam('develocity.allow-untrusted-server'))
|
||||||
|
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url'))
|
||||||
|
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam('develocity.build-scan.upload-in-background'))
|
||||||
|
def develocityCaptureFileFingerprints = getInputParam('develocity.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam('develocity.capture-file-fingerprints')) : true
|
||||||
|
def develocityPluginVersion = getInputParam('develocity.plugin.version')
|
||||||
|
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
|
||||||
|
def buildScanTermsOfUseUrl = getInputParam('develocity.terms-of-use.url')
|
||||||
|
def buildScanTermsOfUseAgree = getInputParam('develocity.terms-of-use.agree')
|
||||||
|
def ciAutoInjectionCustomValueValue = getInputParam('develocity.auto-injection.custom-value')
|
||||||
|
|
||||||
|
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
|
||||||
|
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
|
||||||
|
def shouldApplyDevelocityPlugin = atLeastGradle5 && develocityPluginVersion && isAtLeast(develocityPluginVersion, '3.17')
|
||||||
|
|
||||||
|
def dvOrGe = { def dvValue, def geValue ->
|
||||||
|
if (shouldApplyDevelocityPlugin) {
|
||||||
|
return dvValue instanceof Closure<?> ? dvValue() : dvValue
|
||||||
|
}
|
||||||
|
return geValue instanceof Closure<?> ? geValue() : geValue
|
||||||
}
|
}
|
||||||
return geValue instanceof Closure<?> ? geValue() : geValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// finish early if configuration parameters passed in via system properties are not valid/supported
|
// finish early if configuration parameters passed in via system properties are not valid/supported
|
||||||
if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
|
if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
|
||||||
logger.warn("Common Custom User Data Gradle plugin must be at least 1.7. Configured version is $ccudPluginVersion.")
|
logger.warn("Common Custom User Data Gradle plugin must be at least 1.7. Configured version is $ccudPluginVersion.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conditionally apply and configure the Develocity plugin
|
// Conditionally apply and configure the Develocity plugin
|
||||||
if (GradleVersion.current() < GradleVersion.version('6.0')) {
|
if (GradleVersion.current() < GradleVersion.version('6.0')) {
|
||||||
rootProject {
|
rootProject {
|
||||||
buildscript.configurations.getByName("classpath").incoming.afterResolve { ResolvableDependencies incoming ->
|
buildscript.configurations.getByName("classpath").incoming.afterResolve { ResolvableDependencies incoming ->
|
||||||
def resolutionResult = incoming.resolutionResult
|
def resolutionResult = incoming.resolutionResult
|
||||||
|
|
||||||
if (develocityPluginVersion) {
|
if (develocityPluginVersion) {
|
||||||
def scanPluginComponent = resolutionResult.allComponents.find {
|
def scanPluginComponent = resolutionResult.allComponents.find {
|
||||||
it.moduleVersion.with { group == "com.gradle" && ['build-scan-plugin', 'gradle-enterprise-gradle-plugin', 'develocity-gradle-plugin'].contains(name) }
|
it.moduleVersion.with { group == "com.gradle" && ['build-scan-plugin', 'gradle-enterprise-gradle-plugin', 'develocity-gradle-plugin'].contains(name) }
|
||||||
}
|
|
||||||
if (!scanPluginComponent) {
|
|
||||||
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, BUILD_SCAN_PLUGIN_CLASS)
|
|
||||||
logger.lifecycle("Applying $pluginClass via init script")
|
|
||||||
applyPluginExternally(pluginManager, pluginClass)
|
|
||||||
def rootExtension = dvOrGe(
|
|
||||||
{ develocity },
|
|
||||||
{ buildScan }
|
|
||||||
)
|
|
||||||
def buildScanExtension = dvOrGe(
|
|
||||||
{ rootExtension.buildScan },
|
|
||||||
{ rootExtension }
|
|
||||||
)
|
|
||||||
if (develocityUrl) {
|
|
||||||
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
|
||||||
rootExtension.server = develocityUrl
|
|
||||||
rootExtension.allowUntrustedServer = develocityAllowUntrustedServer
|
|
||||||
}
|
}
|
||||||
if (!shouldApplyDevelocityPlugin) {
|
if (!scanPluginComponent) {
|
||||||
// Develocity plugin publishes scans by default
|
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, BUILD_SCAN_PLUGIN_CLASS)
|
||||||
buildScanExtension.publishAlways()
|
logger.lifecycle("Applying $pluginClass via init script")
|
||||||
}
|
applyPluginExternally(pluginManager, pluginClass)
|
||||||
// uploadInBackground not available for build-scan-plugin 1.16
|
def rootExtension = dvOrGe(
|
||||||
if (buildScanExtension.metaClass.respondsTo(buildScanExtension, 'setUploadInBackground', Boolean)) buildScanExtension.uploadInBackground = buildScanUploadInBackground
|
{ develocity },
|
||||||
buildScanExtension.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
{ buildScan }
|
||||||
if (isAtLeast(develocityPluginVersion, '2.1') && atLeastGradle5) {
|
)
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
def buildScanExtension = dvOrGe(
|
||||||
if (isAtLeast(develocityPluginVersion, '3.17')) {
|
{ rootExtension.buildScan },
|
||||||
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
|
{ rootExtension }
|
||||||
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
|
)
|
||||||
buildScanExtension.capture.taskInputFiles = develocityCaptureFileFingerprints
|
if (develocityUrl) {
|
||||||
} else {
|
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
buildScanExtension.captureTaskInputFiles = develocityCaptureFileFingerprints
|
rootExtension.server = develocityUrl
|
||||||
|
rootExtension.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
|
}
|
||||||
|
if (!shouldApplyDevelocityPlugin) {
|
||||||
|
// Develocity plugin publishes scans by default
|
||||||
|
buildScanExtension.publishAlways()
|
||||||
|
}
|
||||||
|
// uploadInBackground not available for build-scan-plugin 1.16
|
||||||
|
if (buildScanExtension.metaClass.respondsTo(buildScanExtension, 'setUploadInBackground', Boolean)) buildScanExtension.uploadInBackground = buildScanUploadInBackground
|
||||||
|
buildScanExtension.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
||||||
|
if (isAtLeast(develocityPluginVersion, '2.1') && atLeastGradle5) {
|
||||||
|
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
|
if (isAtLeast(develocityPluginVersion, '3.17')) {
|
||||||
|
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
|
||||||
|
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||||
|
buildScanExtension.capture.taskInputFiles = develocityCaptureFileFingerprints
|
||||||
|
} else {
|
||||||
|
buildScanExtension.captureTaskInputFiles = develocityCaptureFileFingerprints
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
|
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
|
||||||
|
// Only execute if develocity plugin isn't applied.
|
||||||
|
if (gradle.rootProject.extensions.findByName("develocity")) return
|
||||||
|
afterEvaluate {
|
||||||
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
|
buildScan.server = develocityUrl
|
||||||
|
buildScan.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||||
|
buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
||||||
|
buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
|
||||||
|
afterEvaluate {
|
||||||
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
|
develocity.server = develocityUrl
|
||||||
|
develocity.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||||
|
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
||||||
|
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ccudPluginVersion && atLeastGradle4) {
|
||||||
|
def ccudPluginComponent = resolutionResult.allComponents.find {
|
||||||
|
it.moduleVersion.with { group == "com.gradle" && name == "common-custom-user-data-gradle-plugin" }
|
||||||
|
}
|
||||||
|
if (!ccudPluginComponent) {
|
||||||
|
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
|
||||||
|
pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gradle.settingsEvaluated { settings ->
|
||||||
|
if (develocityPluginVersion) {
|
||||||
|
if (!settings.pluginManager.hasPlugin(GRADLE_ENTERPRISE_PLUGIN_ID) && !settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
|
||||||
|
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
|
||||||
|
logger.lifecycle("Applying $pluginClass via init script")
|
||||||
|
applyPluginExternally(settings.pluginManager, pluginClass)
|
||||||
|
if (develocityUrl) {
|
||||||
|
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
|
eachDevelocitySettingsExtension(settings) { ext ->
|
||||||
|
ext.server = develocityUrl
|
||||||
|
ext.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eachDevelocitySettingsExtension(settings) { ext ->
|
||||||
|
ext.buildScan.uploadInBackground = buildScanUploadInBackground
|
||||||
|
ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
||||||
|
}
|
||||||
|
|
||||||
|
eachDevelocitySettingsExtension(settings,
|
||||||
|
{ develocity ->
|
||||||
|
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
|
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
||||||
|
},
|
||||||
|
{ gradleEnterprise ->
|
||||||
|
gradleEnterprise.buildScan.publishAlways()
|
||||||
|
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
||||||
|
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
|
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
||||||
|
gradleEnterprise.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
||||||
|
} else {
|
||||||
|
gradleEnterprise.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
|
eachDevelocitySettingsExtension(settings,
|
||||||
// Only execute if develocity plugin isn't applied.
|
{ develocity ->
|
||||||
if (gradle.rootProject.extensions.findByName("develocity")) return
|
|
||||||
afterEvaluate {
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
|
||||||
buildScan.server = develocityUrl
|
|
||||||
buildScan.allowUntrustedServer = develocityAllowUntrustedServer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
|
||||||
buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
|
||||||
buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
|
|
||||||
afterEvaluate {
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
develocity.server = develocityUrl
|
develocity.server = develocityUrl
|
||||||
develocity.allowUntrustedServer = develocityAllowUntrustedServer
|
develocity.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||||
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
||||||
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ccudPluginVersion && atLeastGradle4) {
|
|
||||||
def ccudPluginComponent = resolutionResult.allComponents.find {
|
|
||||||
it.moduleVersion.with { group == "com.gradle" && name == "common-custom-user-data-gradle-plugin" }
|
|
||||||
}
|
|
||||||
if (!ccudPluginComponent) {
|
|
||||||
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
|
|
||||||
pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gradle.settingsEvaluated { settings ->
|
|
||||||
if (develocityPluginVersion) {
|
|
||||||
if (!settings.pluginManager.hasPlugin(GRADLE_ENTERPRISE_PLUGIN_ID) && !settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
|
|
||||||
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
|
|
||||||
logger.lifecycle("Applying $pluginClass via init script")
|
|
||||||
applyPluginExternally(settings.pluginManager, pluginClass)
|
|
||||||
if (develocityUrl) {
|
|
||||||
logger.lifecycle("Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
|
||||||
eachDevelocitySettingsExtension(settings) { ext ->
|
|
||||||
ext.server = develocityUrl
|
|
||||||
ext.allowUntrustedServer = develocityAllowUntrustedServer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eachDevelocitySettingsExtension(settings) { ext ->
|
|
||||||
ext.buildScan.uploadInBackground = buildScanUploadInBackground
|
|
||||||
ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
|
|
||||||
}
|
|
||||||
|
|
||||||
eachDevelocitySettingsExtension(settings,
|
|
||||||
{ develocity ->
|
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
|
||||||
develocity.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
|
|
||||||
},
|
},
|
||||||
{ gradleEnterprise ->
|
{ gradleEnterprise ->
|
||||||
gradleEnterprise.buildScan.publishAlways()
|
if (develocityUrl && develocityEnforceUrl) {
|
||||||
if (isAtLeast(develocityPluginVersion, '2.1')) {
|
gradleEnterprise.server = develocityUrl
|
||||||
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
|
gradleEnterprise.allowUntrustedServer = develocityAllowUntrustedServer
|
||||||
if (isAtLeast(develocityPluginVersion, '3.7')) {
|
}
|
||||||
gradleEnterprise.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
|
|
||||||
} else {
|
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
||||||
gradleEnterprise.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
|
gradleEnterprise.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
||||||
}
|
gradleEnterprise.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
if (ccudPluginVersion) {
|
||||||
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
|
if (!settings.pluginManager.hasPlugin(CCUD_PLUGIN_ID)) {
|
||||||
}
|
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
|
||||||
|
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
||||||
eachDevelocitySettingsExtension(settings,
|
|
||||||
{ develocity ->
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
|
||||||
develocity.server = develocityUrl
|
|
||||||
develocity.allowUntrustedServer = develocityAllowUntrustedServer
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
|
||||||
develocity.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
|
|
||||||
develocity.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ gradleEnterprise ->
|
|
||||||
if (develocityUrl && develocityEnforceUrl) {
|
|
||||||
gradleEnterprise.server = develocityUrl
|
|
||||||
gradleEnterprise.allowUntrustedServer = develocityAllowUntrustedServer
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
|
|
||||||
gradleEnterprise.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
|
|
||||||
gradleEnterprise.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ccudPluginVersion) {
|
|
||||||
if (!settings.pluginManager.hasPlugin(CCUD_PLUGIN_ID)) {
|
|
||||||
logger.lifecycle("Applying $CCUD_PLUGIN_CLASS via init script")
|
|
||||||
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,3 +376,41 @@ static boolean isAtLeast(String versionUnderTest, String referenceVersion) {
|
|||||||
static boolean isNotAtLeast(String versionUnderTest, String referenceVersion) {
|
static boolean isNotAtLeast(String versionUnderTest, String referenceVersion) {
|
||||||
!isAtLeast(versionUnderTest, referenceVersion)
|
!isAtLeast(versionUnderTest, referenceVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enableBuildScanLinkCapture(BuildScanCollector collector) {
|
||||||
|
def BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'
|
||||||
|
def DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
|
||||||
|
|
||||||
|
// Conditionally apply and configure the Develocity plugin
|
||||||
|
if (GradleVersion.current() < GradleVersion.version('6.0')) {
|
||||||
|
rootProject {
|
||||||
|
pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
|
||||||
|
// Only execute if develocity plugin isn't applied.
|
||||||
|
if (gradle.rootProject.extensions.findByName("develocity")) return
|
||||||
|
buildScanPublishedAction(buildScan, collector)
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginManager.withPlugin(DEVELOCITY_PLUGIN_ID) {
|
||||||
|
buildScanPublishedAction(develocity.buildScan, collector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gradle.settingsEvaluated { settings ->
|
||||||
|
eachDevelocitySettingsExtension(settings) { ext ->
|
||||||
|
buildScanPublishedAction(ext.buildScan, collector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action will only be called if a `BuildScanCollector.captureBuildScanLink` method is present.
|
||||||
|
// Add `void captureBuildScanLink(String) {}` to the `BuildScanCollector` class to respond to buildScanPublished events
|
||||||
|
static buildScanPublishedAction(def buildScanExtension, BuildScanCollector collector) {
|
||||||
|
if (buildScanExtension.metaClass.respondsTo(buildScanExtension, 'buildScanPublished', Action)) {
|
||||||
|
buildScanExtension.buildScanPublished { scan ->
|
||||||
|
collector.captureBuildScanLink(scan.buildScanUri.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BuildScanCollector {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user