Inject Develocity plugin for versions 3.17 and above (#62)

To handle the rebranding of the GE plugin, this PR updates the inject-develocity init script 
to apply the `com.gradle.develocity` plugin if `3.17+` version of the plugin is requested.
This commit is contained in:
Pavlo Shevchenko 2024-04-03 22:47:50 +02:00 committed by GitHub
parent 5512434733
commit 5a171ce5b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 440 additions and 201 deletions

View File

@ -24,13 +24,15 @@ jobs:
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_URL: https://ge.solutions-team.gradle.com
DEVELOCITY_PLUGIN_VERSION: 3.16.2
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_CCUD_PLUGIN_VERSION: 1.13
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # This env var has not (yet) been renamed/aliased in GE plugin 3.16.2
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # required to test against GE plugin 3.16.2
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
strategy:
matrix:
gradle: [current, 7.6.2, 6.9.4, 5.6.4]
os: ${{fromJSON(inputs.runner-os)}}
plugin-version: [3.16.2, 3.17]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
@ -81,8 +83,8 @@ jobs:
cache-read-only: false # For testing, allow writing cache entries on non-default branches
gradle-version: ${{ matrix.gradle }}
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
- name: Run Gradle build
id: gradle
working-directory: .github/workflow-samples/no-ge

View File

@ -97,15 +97,15 @@ offending dependency.
### Publishing a Develocity Build Scan® from your dependency submission workflow
You can automatically publish a Build Scan on every run of `gradle/actions/dependency-submission`. Three input parameters are
required, one to enable publishing and two more to accept the [Develocity terms of service](https://gradle.com/terms-of-service).
required, one to enable publishing and two more to accept the [Develocity terms of use](https://gradle.com/help/legal-terms-of-use).
```yaml
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3
with:
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
```
### When you cannot publish a Build Scan®

View File

@ -37,14 +37,14 @@ inputs:
build-scan-publish:
description: |
Set to 'true' to automatically publish build results as a Build Scan on scans.gradle.com.
For publication to succeed without user input, you must also provide values for `build-scan-terms-of-service-url` and 'build-scan-terms-of-service-agree'.
For publication to succeed without user input, you must also provide values for `build-scan-terms-of-use-url` and 'build-scan-terms-of-use-agree'.
required: false
default: false
build-scan-terms-of-service-url:
description: The URL to the Build Scan® terms of service. This input must be set to 'https://gradle.com/terms-of-service'.
build-scan-terms-of-use-url:
description: The URL to the Build Scan® terms of use. This input must be set to 'https://gradle.com/help/legal-terms-of-use'.
required: false
build-scan-terms-of-service-agree:
description: Indicate that you agree to the Build Scan® terms of service. This input value must be "yes".
build-scan-terms-of-use-agree:
description: Indicate that you agree to the Build Scan® terms of use. This input value must be "yes".
required: false
runs:
@ -67,8 +67,8 @@ runs:
build-root-directory: ${{ inputs.build-root-directory }}
cache-encryption-key: ${{ inputs.cache-encryption-key }}
build-scan-publish: ${{ inputs.build-scan-publish }}
build-scan-terms-of-service-url: ${{ inputs.build-scan-terms-of-service-url }}
build-scan-terms-of-service-agree: ${{ inputs.build-scan-terms-of-service-agree }}
build-scan-terms-of-use-url: ${{ inputs.build-scan-terms-of-use-url }}
build-scan-terms-of-use-agree: ${{ inputs.build-scan-terms-of-use-agree }}
artifact-retention-days: 1
arguments: |
-Dorg.gradle.configureondemand=false

View File

@ -139453,19 +139453,22 @@ exports.setup = void 0;
const core = __importStar(__nccwpck_require__(42186));
const input_params_1 = __nccwpck_require__(23885);
function setup() {
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle');
maybeExportVariable('DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE', 'gradle-actions');
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfUseAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true');
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.2');
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.13');
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', (0, input_params_1.getBuildScanTermsOfServiceUrl)());
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', (0, input_params_1.getBuildScanTermsOfServiceAgree)());
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', (0, input_params_1.getBuildScanTermsOfUseUrl)());
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', (0, input_params_1.getBuildScanTermsOfUseAgree)());
}
}
exports.setup = setup;
function verifyTermsOfServiceAgreement() {
if ((0, input_params_1.getBuildScanTermsOfServiceUrl)() !== 'https://gradle.com/terms-of-service' ||
(0, input_params_1.getBuildScanTermsOfServiceAgree)() !== 'yes') {
core.warning(`Terms of service must be agreed in order to publish build scans.`);
function verifyTermsOfUseAgreement() {
if (((0, input_params_1.getBuildScanTermsOfUseUrl)() !== 'https://gradle.com/terms-of-service' &&
(0, input_params_1.getBuildScanTermsOfUseUrl)() !== 'https://gradle.com/help/legal-terms-of-use') ||
(0, input_params_1.getBuildScanTermsOfUseAgree)() !== 'yes') {
core.warning(`Terms of use must be agreed in order to publish build scans.`);
return false;
}
return true;
@ -141322,7 +141325,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfServiceAgree = exports.getBuildScanTermsOfServiceUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfUseAgree = exports.getBuildScanTermsOfUseUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(42186));
const string_argv_1 = __nccwpck_require__(19663);
function isCacheDisabled() {
@ -141402,14 +141405,21 @@ function getBuildScanPublishEnabled() {
return getBooleanInput('build-scan-publish');
}
exports.getBuildScanPublishEnabled = getBuildScanPublishEnabled;
function getBuildScanTermsOfServiceUrl() {
return core.getInput('build-scan-terms-of-service-url');
function getBuildScanTermsOfUseUrl() {
return getTermsOfUseProp('build-scan-terms-of-use-url', 'build-scan-terms-of-service-url');
}
exports.getBuildScanTermsOfServiceUrl = getBuildScanTermsOfServiceUrl;
function getBuildScanTermsOfServiceAgree() {
return core.getInput('build-scan-terms-of-service-agree');
exports.getBuildScanTermsOfUseUrl = getBuildScanTermsOfUseUrl;
function getBuildScanTermsOfUseAgree() {
return getTermsOfUseProp('build-scan-terms-of-use-agree', 'build-scan-terms-of-service-agree');
}
exports.getBuildScanTermsOfUseAgree = getBuildScanTermsOfUseAgree;
function getTermsOfUseProp(newPropName, oldPropName) {
const newProp = core.getInput(newPropName);
if (newProp !== '') {
return newProp;
}
return core.getInput(oldPropName);
}
exports.getBuildScanTermsOfServiceAgree = getBuildScanTermsOfServiceAgree;
function parseJobSummaryOption(paramName) {
const val = core.getInput(paramName);
switch (val.toLowerCase().trim()) {

File diff suppressed because one or more lines are too long

View File

@ -136906,19 +136906,22 @@ exports.setup = void 0;
const core = __importStar(__nccwpck_require__(42186));
const input_params_1 = __nccwpck_require__(23885);
function setup() {
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle');
maybeExportVariable('DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE', 'gradle-actions');
if ((0, input_params_1.getBuildScanPublishEnabled)() && verifyTermsOfUseAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true');
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.2');
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.13');
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', (0, input_params_1.getBuildScanTermsOfServiceUrl)());
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', (0, input_params_1.getBuildScanTermsOfServiceAgree)());
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', (0, input_params_1.getBuildScanTermsOfUseUrl)());
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', (0, input_params_1.getBuildScanTermsOfUseAgree)());
}
}
exports.setup = setup;
function verifyTermsOfServiceAgreement() {
if ((0, input_params_1.getBuildScanTermsOfServiceUrl)() !== 'https://gradle.com/terms-of-service' ||
(0, input_params_1.getBuildScanTermsOfServiceAgree)() !== 'yes') {
core.warning(`Terms of service must be agreed in order to publish build scans.`);
function verifyTermsOfUseAgreement() {
if (((0, input_params_1.getBuildScanTermsOfUseUrl)() !== 'https://gradle.com/terms-of-service' &&
(0, input_params_1.getBuildScanTermsOfUseUrl)() !== 'https://gradle.com/help/legal-terms-of-use') ||
(0, input_params_1.getBuildScanTermsOfUseAgree)() !== 'yes') {
core.warning(`Terms of use must be agreed in order to publish build scans.`);
return false;
}
return true;
@ -138641,7 +138644,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfServiceAgree = exports.getBuildScanTermsOfServiceUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.JobSummaryOption = exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphContinueOnFailure = exports.getDependencyGraphOption = exports.getBuildScanTermsOfUseAgree = exports.getBuildScanTermsOfUseUrl = exports.getBuildScanPublishEnabled = exports.getPRCommentOption = exports.getJobSummaryOption = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.getCacheEncryptionKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(42186));
const string_argv_1 = __nccwpck_require__(19663);
function isCacheDisabled() {
@ -138721,14 +138724,21 @@ function getBuildScanPublishEnabled() {
return getBooleanInput('build-scan-publish');
}
exports.getBuildScanPublishEnabled = getBuildScanPublishEnabled;
function getBuildScanTermsOfServiceUrl() {
return core.getInput('build-scan-terms-of-service-url');
function getBuildScanTermsOfUseUrl() {
return getTermsOfUseProp('build-scan-terms-of-use-url', 'build-scan-terms-of-service-url');
}
exports.getBuildScanTermsOfServiceUrl = getBuildScanTermsOfServiceUrl;
function getBuildScanTermsOfServiceAgree() {
return core.getInput('build-scan-terms-of-service-agree');
exports.getBuildScanTermsOfUseUrl = getBuildScanTermsOfUseUrl;
function getBuildScanTermsOfUseAgree() {
return getTermsOfUseProp('build-scan-terms-of-use-agree', 'build-scan-terms-of-service-agree');
}
exports.getBuildScanTermsOfUseAgree = getBuildScanTermsOfUseAgree;
function getTermsOfUseProp(newPropName, oldPropName) {
const newProp = core.getInput(newPropName);
if (newProp !== '') {
return newProp;
}
return core.getInput(oldPropName);
}
exports.getBuildScanTermsOfServiceAgree = getBuildScanTermsOfServiceAgree;
function parseJobSummaryOption(paramName) {
const val = core.getInput(paramName);
switch (val.toLowerCase().trim()) {

File diff suppressed because one or more lines are too long

View File

@ -688,7 +688,7 @@ The `init-script` supports several additional configuration parameters that you
Develocity injection is designed to enable the publishing of build scans to a Develocity instance,
but is also useful for publishing to the public Build Scans instance (https://scans.gradle.com).
To publish to https://scans.gradle.com, you must specify in your workflow that you accept the [Gradle Terms of Service](https://gradle.com/terms-of-service).
To publish to https://scans.gradle.com, you must specify in your workflow that you accept the [Gradle Terms of Use](https://gradle.com/help/legal-terms-of-use).
```yaml
name: Run build and publish Build Scan
@ -702,8 +702,8 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
build-scan-publish: true
build-scan-terms-of-service-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-service-agree: "yes"
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
- name: Run a Gradle build - a build scan will be published automatically
run: ./gradlew build

View File

@ -85,19 +85,29 @@ inputs:
build-scan-publish:
description: |
Set to 'true' to automatically publish build results as a Build Scan on scans.gradle.com.
For publication to succeed without user input, you must also provide values for `build-scan-terms-of-service-url` and 'build-scan-terms-of-service-agree'.
For publication to succeed without user input, you must also provide values for `build-scan-terms-of-use-url` and 'build-scan-terms-of-use-agree'.
required: false
default: false
build-scan-terms-of-service-url:
description: The URL to the Build Scan® terms of service. This input must be set to 'https://gradle.com/terms-of-service'.
build-scan-terms-of-use-url:
description: The URL to the Build Scan® terms of use. This input must be set to 'https://gradle.com/terms-of-service' or 'https://gradle.com/help/legal-terms-of-use'.
required: false
build-scan-terms-of-service-agree:
description: Indicate that you agree to the Build Scan® terms of service. This input value must be "yes".
build-scan-terms-of-use-agree:
description: Indicate that you agree to the Build Scan® terms of use. This input value must be "yes".
required: false
# DEPRECATED ACTION INPUTS
build-scan-terms-of-service-url:
description: The URL to the Build Scan® terms of use. This input must be set to 'https://gradle.com/terms-of-service'.
required: false
deprecation-message: The input has been renamed to align with the Develocity API. Use 'build-scan-terms-of-use-url' instead.
build-scan-terms-of-service-agree:
description: Indicate that you agree to the Build Scan® terms of use. This input value must be "yes".
required: false
deprecation-message: The input has been renamed to align with the Develocity API. Use 'build-scan-terms-of-use-agree' instead.
arguments:
description: Gradle command line arguments (supports multi-line input)
required: false

View File

@ -1,26 +1,25 @@
import * as core from '@actions/core'
import {
getBuildScanPublishEnabled,
getBuildScanTermsOfServiceUrl,
getBuildScanTermsOfServiceAgree
} from './input-params'
import {getBuildScanPublishEnabled, getBuildScanTermsOfUseUrl, getBuildScanTermsOfUseAgree} from './input-params'
export function setup(): void {
if (getBuildScanPublishEnabled() && verifyTermsOfServiceAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
maybeExportVariable('DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE', 'gradle-actions')
if (getBuildScanPublishEnabled() && verifyTermsOfUseAgreement()) {
maybeExportVariable('DEVELOCITY_INJECTION_ENABLED', 'true')
maybeExportVariable('DEVELOCITY_PLUGIN_VERSION', '3.16.2')
maybeExportVariable('DEVELOCITY_CCUD_PLUGIN_VERSION', '1.13')
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_URL', getBuildScanTermsOfServiceUrl())
maybeExportVariable('BUILD_SCAN_TERMS_OF_SERVICE_AGREE', getBuildScanTermsOfServiceAgree())
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', getBuildScanTermsOfUseAgree())
}
}
function verifyTermsOfServiceAgreement(): boolean {
function verifyTermsOfUseAgreement(): boolean {
if (
getBuildScanTermsOfServiceUrl() !== 'https://gradle.com/terms-of-service' ||
getBuildScanTermsOfServiceAgree() !== 'yes'
(getBuildScanTermsOfUseUrl() !== 'https://gradle.com/terms-of-service' &&
getBuildScanTermsOfUseUrl() !== 'https://gradle.com/help/legal-terms-of-use') ||
getBuildScanTermsOfUseAgree() !== 'yes'
) {
core.warning(`Terms of service must be agreed in order to publish build scans.`)
core.warning(`Terms of use must be agreed in order to publish build scans.`)
return false
}
return true

View File

@ -79,12 +79,23 @@ export function getBuildScanPublishEnabled(): boolean {
return getBooleanInput('build-scan-publish')
}
export function getBuildScanTermsOfServiceUrl(): string {
return core.getInput('build-scan-terms-of-service-url')
export function getBuildScanTermsOfUseUrl(): string {
return getTermsOfUseProp('build-scan-terms-of-use-url', 'build-scan-terms-of-service-url')
}
export function getBuildScanTermsOfServiceAgree(): string {
return core.getInput('build-scan-terms-of-service-agree')
export function getBuildScanTermsOfUseAgree(): string {
return getTermsOfUseProp('build-scan-terms-of-use-agree', 'build-scan-terms-of-service-agree')
}
/**
* TODO @bigdaz: remove the deprecated input property in the next major release of the action
*/
function getTermsOfUseProp(newPropName: string, oldPropName: string): string {
const newProp = core.getInput(newPropName)
if (newProp !== '') {
return newProp
}
return core.getInput(oldPropName)
}
function parseJobSummaryOption(paramName: string): JobSummaryOption {

View File

@ -28,6 +28,9 @@ if (isTopLevelBuild) {
settings.pluginManager.withPlugin("com.gradle.enterprise") {
captureUsingBuildScanPublished(settings.extensions["gradleEnterprise"].buildScan, settings.rootProject, invocationId)
}
settings.pluginManager.withPlugin("com.gradle.develocity") {
captureUsingBuildScanPublished(settings.extensions["develocity"].buildScan, settings.rootProject, invocationId)
}
}
} else if (atLeastGradle3) {
projectsEvaluated { gradle ->
@ -104,7 +107,13 @@ class BuildResults {
}
def setBuildResult(def result) {
buildResults['buildFailed'] = result.failure != null
try {
// Gradle and old Build Scan/Gradle Enterprise plugins report a single optional failure in the build result
buildResults['buildFailed'] = result.failure != null
} catch (Exception e) {
// Develocity plugin unwraps all build failures and reports them as a mandatory array
buildResults['buildFailed'] = !result.failures.empty
}
}
def setBuildScanUri(def buildScanUrl) {

View File

@ -2,7 +2,7 @@ import org.gradle.util.GradleVersion
// note that there is no mechanism to share code between the initscript{} block and the main script, so some logic is duplicated
// conditionally apply the GE / Build Scan plugin to the classpath so it can be applied to the build further down in this script
// conditionally apply the Develocity plugin to the classpath so it can be applied to the build further down in this script
initscript {
def isTopLevelBuild = !gradle.parent
if (!isTopLevelBuild) {
@ -14,6 +14,12 @@ initscript {
return System.getProperty(name) ?: System.getenv(envVarName)
}
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
return
}
// finish early if injection is disabled
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
if (gradleInjectionEnabled != "true") {
@ -23,13 +29,13 @@ initscript {
def pluginRepositoryUrl = getInputParam('gradle.plugin-repository.url')
def pluginRepositoryUsername = getInputParam('gradle.plugin-repository.username')
def pluginRepositoryPassword = getInputParam('gradle.plugin-repository.password')
def gePluginVersion = getInputParam('develocity.plugin.version')
def develocityPluginVersion = getInputParam('develocity.plugin.version')
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
if (gePluginVersion || ccudPluginVersion && atLeastGradle4) {
if (develocityPluginVersion || ccudPluginVersion && atLeastGradle4) {
pluginRepositoryUrl = pluginRepositoryUrl ?: 'https://plugins.gradle.org/m2'
logger.lifecycle("Develocity plugins resolution: $pluginRepositoryUrl")
@ -51,10 +57,16 @@ initscript {
}
dependencies {
if (gePluginVersion) {
classpath atLeastGradle5 ?
"com.gradle:gradle-enterprise-gradle-plugin:$gePluginVersion" :
"com.gradle:build-scan-plugin:1.16"
if (develocityPluginVersion) {
if (atLeastGradle5) {
if (GradleVersion.version(develocityPluginVersion) >= GradleVersion.version("3.17")) {
classpath "com.gradle:develocity-gradle-plugin:$develocityPluginVersion"
} else {
classpath "com.gradle:gradle-enterprise-gradle-plugin:$develocityPluginVersion"
}
} else {
classpath "com.gradle:build-scan-plugin:1.16"
}
}
if (ccudPluginVersion && atLeastGradle4) {
@ -66,11 +78,17 @@ initscript {
def BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'
def BUILD_SCAN_PLUGIN_CLASS = 'com.gradle.scan.plugin.BuildScanPlugin'
def DEVELOCITY_PLUGIN_ID = 'com.gradle.enterprise'
def DEVELOCITY_PLUGIN_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin'
def DEVELOCITY_EXTENSION_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension'
def GRADLE_ENTERPRISE_PLUGIN_ID = 'com.gradle.enterprise'
def GRADLE_ENTERPRISE_PLUGIN_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin'
def GRADLE_ENTERPRISE_EXTENSION_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension'
def DEVELOCITY_PLUGIN_ID = 'com.gradle.develocity'
def DEVELOCITY_PLUGIN_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityPlugin'
def DEVELOCITY_CONFIGURATION_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityConfiguration'
def SETTINGS_EXTENSION_CLASSES = [GRADLE_ENTERPRISE_EXTENSION_CLASS, DEVELOCITY_CONFIGURATION_CLASS]
def CI_AUTO_INJECTION_CUSTOM_VALUE_NAME = 'CI auto injection'
def CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE = 'gradle-actions'
def CCUD_PLUGIN_ID = 'com.gradle.common-custom-user-data-gradle-plugin'
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
@ -84,24 +102,40 @@ def getInputParam = { String name ->
return System.getProperty(name) ?: System.getenv(envVarName)
}
def requestedInitScriptName = getInputParam('develocity.injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
if (requestedInitScriptName != initScriptName) {
logger.quiet("Ignoring init script '${initScriptName}' as requested name '${requestedInitScriptName}' does not match")
return
}
// finish early if injection is disabled
def gradleInjectionEnabled = getInputParam("develocity.injection-enabled")
if (gradleInjectionEnabled != "true") {
return
}
def geUrl = getInputParam('develocity.url')
def geAllowUntrustedServer = Boolean.parseBoolean(getInputParam('develocity.allow-untrusted-server'))
def geEnforceUrl = Boolean.parseBoolean(getInputParam('develocity.enforce-url'))
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 gePluginVersion = getInputParam('develocity.plugin.version')
def develocityPluginVersion = getInputParam('develocity.plugin.version')
def ccudPluginVersion = getInputParam('develocity.ccud-plugin.version')
def buildScanTermsOfServiceUrl = getInputParam('build-scan.terms-of-service.url')
def buildScanTermsOfServiceAgree = getInputParam('build-scan.terms-of-service.agree')
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
}
// finish early if configuration parameters passed in via system properties are not valid/supported
if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
@ -109,50 +143,82 @@ if (ccudPluginVersion && isNotAtLeast(ccudPluginVersion, '1.7')) {
return
}
// register buildScanPublished listener and optionally apply the GE / Build Scan plugin
// register buildScanPublished listener and optionally apply the Develocity plugin
if (GradleVersion.current() < GradleVersion.version('6.0')) {
rootProject {
buildscript.configurations.getByName("classpath").incoming.afterResolve { ResolvableDependencies incoming ->
def resolutionResult = incoming.resolutionResult
if (gePluginVersion) {
if (develocityPluginVersion) {
def scanPluginComponent = resolutionResult.allComponents.find {
it.moduleVersion.with { group == "com.gradle" && (name == "build-scan-plugin" || name == "gradle-enterprise-gradle-plugin") }
it.moduleVersion.with { group == "com.gradle" && ['build-scan-plugin', 'gradle-enterprise-gradle-plugin', 'develocity-gradle-plugin'].contains(name) }
}
if (!scanPluginComponent) {
logger.lifecycle("Applying $BUILD_SCAN_PLUGIN_CLASS via init script")
applyPluginExternally(pluginManager, BUILD_SCAN_PLUGIN_CLASS)
if (geUrl) {
logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
buildScan.server = geUrl
buildScan.allowUntrustedServer = geAllowUntrustedServer
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
}
buildScan.publishAlways()
if (buildScan.metaClass.respondsTo(buildScan, 'setUploadInBackground', Boolean)) buildScan.uploadInBackground = buildScanUploadInBackground // uploadInBackground not available for build-scan-plugin 1.16
buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE
if (isAtLeast(gePluginVersion, '2.1') && atLeastGradle5) {
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(gePluginVersion, '3.7')) {
buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
if (isAtLeast(develocityPluginVersion, '3.17')) {
buildScanExtension.capture.fileFingerprints.set(develocityCaptureFileFingerprints)
} else if (isAtLeast(develocityPluginVersion, '3.7')) {
buildScanExtension.capture.taskInputFiles = develocityCaptureFileFingerprints
} else {
buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
buildScanExtension.captureTaskInputFiles = develocityCaptureFileFingerprints
}
}
}
if (geUrl && geEnforceUrl) {
pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
afterEvaluate {
logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
buildScan.server = geUrl
buildScan.allowUntrustedServer = geAllowUntrustedServer
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
}
pluginManager.withPlugin(BUILD_SCAN_PLUGIN_ID) {
afterEvaluate {
if (develocityUrl && develocityEnforceUrl) {
buildScan.server = develocityUrl
buildScan.allowUntrustedServer = develocityAllowUntrustedServer
}
}
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
}
}
if (buildScanTermsOfServiceUrl && buildScanTermsOfServiceAgree) {
buildScan.termsOfServiceUrl = buildScanTermsOfServiceUrl
buildScan.termsOfServiceAgree = buildScanTermsOfServiceAgree
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
}
}
}
@ -169,42 +235,66 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
}
} else {
gradle.settingsEvaluated { settings ->
if (gePluginVersion) {
if (!settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
logger.lifecycle("Applying $DEVELOCITY_PLUGIN_CLASS via init script")
applyPluginExternally(settings.pluginManager, DEVELOCITY_PLUGIN_CLASS)
eachDevelocityExtension(settings, DEVELOCITY_EXTENSION_CLASS) { ext ->
if (geUrl) {
logger.lifecycle("Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
ext.server = geUrl
ext.allowUntrustedServer = geAllowUntrustedServer
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, SETTINGS_EXTENSION_CLASSES) { ext ->
ext.server = develocityUrl
ext.allowUntrustedServer = develocityAllowUntrustedServer
}
ext.buildScan.publishAlways()
}
eachDevelocitySettingsExtension(settings, SETTINGS_EXTENSION_CLASSES) { ext ->
ext.buildScan.uploadInBackground = buildScanUploadInBackground
if (isAtLeast(gePluginVersion, '2.1')) {
ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, ciAutoInjectionCustomValueValue
}
eachDevelocitySettingsExtension(settings, [GRADLE_ENTERPRISE_EXTENSION_CLASS]) { ext ->
ext.buildScan.publishAlways()
if (isAtLeast(develocityPluginVersion, '2.1')) {
logger.lifecycle("Setting captureFileFingerprints: $develocityCaptureFileFingerprints")
if (isAtLeast(gePluginVersion, '3.7')) {
if (isAtLeast(develocityPluginVersion, '3.7')) {
ext.buildScan.capture.taskInputFiles = develocityCaptureFileFingerprints
} else {
ext.buildScan.captureTaskInputFiles = develocityCaptureFileFingerprints
}
}
ext.buildScan.value CI_AUTO_INJECTION_CUSTOM_VALUE_NAME, CI_AUTO_INJECTION_CUSTOM_VALUE_VALUE
}
eachDevelocitySettingsExtension(settings, [DEVELOCITY_CONFIGURATION_CLASS]) { ext ->
ext.buildScan.capture.fileFingerprints = develocityCaptureFileFingerprints
}
}
if (geUrl && geEnforceUrl) {
eachDevelocityExtension(settings, DEVELOCITY_EXTENSION_CLASS) { ext ->
logger.lifecycle("Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer")
ext.server = geUrl
ext.allowUntrustedServer = geAllowUntrustedServer
if (develocityUrl && develocityEnforceUrl) {
logger.lifecycle("Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer, captureFileFingerprints: $develocityCaptureFileFingerprints")
}
eachDevelocitySettingsExtension(settings, [GRADLE_ENTERPRISE_EXTENSION_CLASS]) { ext ->
if (develocityUrl && develocityEnforceUrl) {
ext.server = develocityUrl
ext.allowUntrustedServer = develocityAllowUntrustedServer
}
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
ext.buildScan.termsOfServiceUrl = buildScanTermsOfUseUrl
ext.buildScan.termsOfServiceAgree = buildScanTermsOfUseAgree
}
}
if (buildScanTermsOfServiceUrl && buildScanTermsOfServiceAgree) {
eachDevelocityExtension(settings, DEVELOCITY_EXTENSION_CLASS) { ext ->
ext.buildScan.termsOfServiceUrl = buildScanTermsOfServiceUrl
ext.buildScan.termsOfServiceAgree = buildScanTermsOfServiceAgree
eachDevelocitySettingsExtension(settings, [DEVELOCITY_CONFIGURATION_CLASS]) { ext ->
if (develocityUrl && develocityEnforceUrl) {
ext.server = develocityUrl
ext.allowUntrustedServer = develocityAllowUntrustedServer
}
if (buildScanTermsOfUseUrl && buildScanTermsOfUseAgree) {
ext.buildScan.termsOfUseUrl = buildScanTermsOfUseUrl
ext.buildScan.termsOfUseAgree = buildScanTermsOfUseAgree
}
}
}
@ -220,8 +310,11 @@ if (GradleVersion.current() < GradleVersion.version('6.0')) {
void applyPluginExternally(def pluginManager, String pluginClassName) {
def externallyApplied = 'develocity.externally-applied'
def externallyAppliedDeprecated = 'gradle.enterprise.externally-applied'
def oldValue = System.getProperty(externallyApplied)
def oldValueDeprecated = System.getProperty(externallyAppliedDeprecated)
System.setProperty(externallyApplied, 'true')
System.setProperty(externallyAppliedDeprecated, 'true')
try {
pluginManager.apply(initscript.classLoader.loadClass(pluginClassName))
} finally {
@ -230,18 +323,24 @@ void applyPluginExternally(def pluginManager, String pluginClassName) {
} else {
System.setProperty(externallyApplied, oldValue)
}
if (oldValueDeprecated == null) {
System.clearProperty(externallyAppliedDeprecated)
} else {
System.setProperty(externallyAppliedDeprecated, oldValueDeprecated)
}
}
}
static def eachDevelocityExtension(def settings, def publicType, def action) {
settings.extensions.extensionsSchema.elements.findAll { it.publicType.concreteClass.name == publicType }
.collect { settings[it.name] }.each(action)
}
static boolean isNotAtLeast(String versionUnderTest, String referenceVersion) {
!isAtLeast(versionUnderTest, referenceVersion)
static def eachDevelocitySettingsExtension(def settings, List<String> publicTypes, def action) {
settings.extensions.extensionsSchema.elements.findAll { publicTypes.contains(it.publicType.concreteClass.name) }
.collect { settings[it.name] }
.each(action)
}
static boolean isAtLeast(String versionUnderTest, String referenceVersion) {
GradleVersion.version(versionUnderTest) >= GradleVersion.version(referenceVersion)
}
static boolean isNotAtLeast(String versionUnderTest, String referenceVersion) {
!isAtLeast(versionUnderTest, referenceVersion)
}

View File

@ -16,7 +16,7 @@ import java.nio.file.Files
import java.util.zip.GZIPOutputStream
class BaseInitScriptTest extends Specification {
static final String DEVELOCITY_PLUGIN_VERSION = '3.16.2'
static final String DEVELOCITY_PLUGIN_VERSION = '3.17'
static final String CCUD_PLUGIN_VERSION = '1.13'
static final TestGradleVersion GRADLE_3_X = new TestGradleVersion(GradleVersion.version('3.5.1'), 7, 9)
@ -129,33 +129,26 @@ class BaseInitScriptTest extends Specification {
buildFile << ''
}
def declareGePluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
def declareDevelocityPluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, null, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, null, serverUrl) + buildFile.text
}
def declareGePluginAndCcudPluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
def declareDevelocityPluginAndCcudPluginApplication(GradleVersion gradleVersion, URI serverUrl = mockScansServer.address) {
settingsFile.text = maybeAddPluginsToSettings(gradleVersion, CCUD_PLUGIN_VERSION, serverUrl) + settingsFile.text
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, CCUD_PLUGIN_VERSION, serverUrl) + buildFile.text
}
String maybeAddPluginsToSettings(GradleVersion gradleVersion, String ccudPluginVersion, URI serverUri) {
if (gradleVersion < GradleVersion.version('5.0')) {
'' // applied in build.gradle
} else if (gradleVersion < GradleVersion.version('6.0')) {
if (gradleVersion < GradleVersion.version('6.0')) {
'' // applied in build.gradle
} else {
"""
plugins {
id 'com.gradle.enterprise' version '${DEVELOCITY_PLUGIN_VERSION}'
id 'com.gradle.develocity' version '${DEVELOCITY_PLUGIN_VERSION}'
${ccudPluginVersion ? "id 'com.gradle.common-custom-user-data-gradle-plugin' version '$ccudPluginVersion'" : ""}
}
gradleEnterprise {
server = '$serverUri'
buildScan {
publishAlways()
}
}
develocity.server = '$serverUri'
"""
}
}
@ -175,15 +168,10 @@ class BaseInitScriptTest extends Specification {
} else if (gradleVersion < GradleVersion.version('6.0')) {
"""
plugins {
id 'com.gradle.build-scan' version '${DEVELOCITY_PLUGIN_VERSION}'
id 'com.gradle.develocity' version '${DEVELOCITY_PLUGIN_VERSION}'
${ccudPluginVersion ? "id 'com.gradle.common-custom-user-data-gradle-plugin' version '$ccudPluginVersion'" : ""}
}
gradleEnterprise {
server = '$serverUrl'
buildScan {
publishAlways()
}
}
develocity.server = '$serverUrl'
"""
} else {
'' // applied in settings.gradle

View File

@ -58,7 +58,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
run(['help'], initScript, testGradleVersion.gradleVersion)
then:
@ -68,11 +68,11 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
testGradleVersion << ALL_VERSIONS
}
def "produces build results file for #testGradleVersion with ge-plugin and no build scan published"() {
def "produces build results file for #testGradleVersion with Develocity plugin and no build scan published"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
run(['help', '--no-scan'], initScript, testGradleVersion.gradleVersion)
then:
@ -86,7 +86,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
addFailingTaskToBuild()
runAndFail(['expectFailure'], initScript, testGradleVersion.gradleVersion)
@ -101,7 +101,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion)
then:
@ -122,7 +122,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
addFailingTaskToBuild()
failScanUpload = true
runAndFail(['expectFailure'], initScript, testGradleVersion.gradleVersion)
@ -165,7 +165,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
testGradleVersion << ALL_VERSIONS
}
def "produces build results file with build scan when GE plugin is applied in settingsEvaluated"() {
def "produces build results file with build scan when Develocity plugin is applied in settingsEvaluated"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:

View File

@ -2,6 +2,7 @@ package com.gradle.gradlebuildaction
import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import spock.lang.Requires
import static org.junit.Assume.assumeTrue
@ -10,7 +11,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def initScript = 'gradle-actions.inject-develocity.init.gradle'
private static final GradleVersion GRADLE_6 = GradleVersion.version('6.0')
private static final GradleVersion GRADLE_5 = GradleVersion.version('5.0')
def "does not apply Develocity plugins when not requested"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
@ -30,7 +31,32 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
when:
def result = run(testGradleVersion, testConfig())
then:
outputMissesDevelocityPluginApplicationViaInitScript(result)
outputMissesCcudPluginApplicationViaInitScript(result)
and:
outputContainsBuildScanUrl(result)
where:
testGradleVersion << ALL_VERSIONS
}
@Requires(
value = { data.testGradleVersion.gradleVersion >= GradleVersion.version("5.0") },
reason = "Prior to Gradle 5.0, we apply a fixed version of the plugin, which can't introduce this conflict"
)
def "does not override GE or Build Scan plugins even if Develocity plugin is requested"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
settingsFile.text = maybeAddGradleEnterprisePlugin(testGradleVersion.gradleVersion, '3.16.2')
buildFile.text = maybeAddBuildScanPlugin(testGradleVersion.gradleVersion, '3.16.2')
when:
def result = run(testGradleVersion, testConfig())
@ -63,6 +89,28 @@ class TestDevelocityInjection extends BaseInitScriptTest {
testGradleVersion << ALL_VERSIONS
}
def "applies deprecated Gradle Enterprise or Build Scan plugins if requested"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
def appliedPluginClass = testGradleVersion.gradleVersion >= GradleVersion.version("6.0")
? "com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin"
: "com.gradle.scan.plugin.BuildScanPlugin"
when:
// 3.16.2 is the latest version of deprecated plugins
def result = run(testGradleVersion, testConfig('3.16.2'))
then:
1 == result.output.count("Applying $appliedPluginClass via init script")
and:
outputContainsBuildScanUrl(result)
where:
testGradleVersion << ALL_VERSIONS
}
def "applies Develocity and CCUD plugins via init script when not defined in project"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
@ -84,7 +132,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
when:
def result = run(testGradleVersion, testConfig().withCCUDPlugin())
@ -104,7 +152,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareGePluginAndCcudPluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginAndCcudPluginApplication(testGradleVersion.gradleVersion)
when:
def result = run(testGradleVersion, testConfig().withCCUDPlugin())
@ -124,7 +172,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareGePluginApplication(testGradleVersion.gradleVersion)
declareDevelocityPluginApplication(testGradleVersion.gradleVersion)
when:
def config = testConfig().withServer(URI.create('https://develocity-server.invalid'))
@ -165,7 +213,7 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareGePluginApplication(testGradleVersion.gradleVersion, URI.create('https://develocity-server.invalid'))
declareDevelocityPluginApplication(testGradleVersion.gradleVersion, URI.create('https://develocity-server.invalid'))
when:
def config = testConfig().withServer(mockScansServer.address, true)
@ -316,24 +364,24 @@ class TestDevelocityInjection extends BaseInitScriptTest {
}
void outputContainsDevelocityPluginApplicationViaInitScript(BuildResult result, GradleVersion gradleVersion) {
def pluginApplicationLogMsgGradle4And5 = "Applying com.gradle.scan.plugin.BuildScanPlugin via init script"
def pluginApplicationLogMsgGradle6AndHigher = "Applying com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin via init script"
if (gradleVersion < GRADLE_6) {
assert result.output.contains(pluginApplicationLogMsgGradle4And5)
assert 1 == result.output.count(pluginApplicationLogMsgGradle4And5)
assert !result.output.contains(pluginApplicationLogMsgGradle6AndHigher)
def pluginApplicationLogMsgGradle4 = "Applying com.gradle.scan.plugin.BuildScanPlugin via init script"
def pluginApplicationLogMsgGradle5AndHigher = "Applying com.gradle.develocity.agent.gradle.DevelocityPlugin via init script"
if (gradleVersion < GRADLE_5) {
assert result.output.contains(pluginApplicationLogMsgGradle4)
assert 1 == result.output.count(pluginApplicationLogMsgGradle4)
assert !result.output.contains(pluginApplicationLogMsgGradle5AndHigher)
} else {
assert result.output.contains(pluginApplicationLogMsgGradle6AndHigher)
assert 1 == result.output.count(pluginApplicationLogMsgGradle6AndHigher)
assert !result.output.contains(pluginApplicationLogMsgGradle4And5)
assert result.output.contains(pluginApplicationLogMsgGradle5AndHigher)
assert 1 == result.output.count(pluginApplicationLogMsgGradle5AndHigher)
assert !result.output.contains(pluginApplicationLogMsgGradle4)
}
}
void outputMissesDevelocityPluginApplicationViaInitScript(BuildResult result) {
def pluginApplicationLogMsgGradle4And5 = "Applying com.gradle.scan.plugin.BuildScanPlugin via init script"
def pluginApplicationLogMsgGradle6AndHigher = "Applying com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin via init script"
assert !result.output.contains(pluginApplicationLogMsgGradle4And5)
assert !result.output.contains(pluginApplicationLogMsgGradle6AndHigher)
def pluginApplicationLogMsgGradle4 = "Applying com.gradle.scan.plugin.BuildScanPlugin via init script"
def pluginApplicationLogMsgGradle5AndHigher = "Applying com.gradle.develocity.agent.gradle.DevelocityPlugin via init script"
assert !result.output.contains(pluginApplicationLogMsgGradle4)
assert !result.output.contains(pluginApplicationLogMsgGradle5AndHigher)
}
void outputContainsCcudPluginApplicationViaInitScript(BuildResult result) {
@ -347,10 +395,10 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assert !result.output.contains(pluginApplicationLogMsg)
}
void outputContainsDevelocityConnectionInfo(BuildResult result, String geUrl, boolean geAllowUntrustedServer) {
def geConnectionInfo = "Connection to Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer"
assert result.output.contains(geConnectionInfo)
assert 1 == result.output.count(geConnectionInfo)
void outputContainsDevelocityConnectionInfo(BuildResult result, String develocityUrl, boolean develocityAllowUntrustedServer) {
def develocityConnectionInfo = "Connection to Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer"
assert result.output.contains(develocityConnectionInfo)
assert 1 == result.output.count(develocityConnectionInfo)
}
void outputCaptureFileFingerprints(BuildResult result, boolean captureFileFingerprints) {
@ -371,8 +419,8 @@ class TestDevelocityInjection extends BaseInitScriptTest {
}
}
void outputEnforcesDevelocityUrl(BuildResult result, String geUrl, boolean geAllowUntrustedServer) {
def enforceUrl = "Enforcing Develocity: $geUrl, allowUntrustedServer: $geAllowUntrustedServer"
void outputEnforcesDevelocityUrl(BuildResult result, String develocityUrl, boolean develocityAllowUntrustedServer) {
def enforceUrl = "Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer"
assert result.output.contains(enforceUrl)
assert 1 == result.output.count(enforceUrl)
}
@ -395,8 +443,52 @@ class TestDevelocityInjection extends BaseInitScriptTest {
}
}
private TestConfig testConfig() {
new TestConfig()
private String maybeAddGradleEnterprisePlugin(GradleVersion gradleVersion, String gePluginVersion) {
if (gradleVersion < GradleVersion.version('6.0')) {
'' // applied in build.gradle
} else {
"""
plugins {
id 'com.gradle.enterprise' version '${gePluginVersion}'
}
gradleEnterprise {
server = '${mockScansServer.address}'
buildScan {
publishAlways()
}
}
"""
}
}
private String maybeAddBuildScanPlugin(GradleVersion gradleVersion, String buildScanPluginVersion) {
if (gradleVersion < GradleVersion.version('5.0')) {
"""
plugins {
id 'com.gradle.build-scan' version '1.16'
}
buildScan {
server = '${mockScansServer.address}'
publishAlways()
}
"""
} else if (gradleVersion < GradleVersion.version('6.0')) {
"""
plugins {
id 'com.gradle.build-scan' version '${buildScanPluginVersion}'
}
buildScan {
server = '${mockScansServer.address}'
publishAlways()
}
"""
} else {
'' // applied in settings.gradle
}
}
private TestConfig testConfig(String develocityPluginVersion = DEVELOCITY_PLUGIN_VERSION) {
new TestConfig(develocityPluginVersion)
}
class TestConfig {
@ -407,6 +499,11 @@ class TestDevelocityInjection extends BaseInitScriptTest {
String pluginRepositoryUsername = null
String pluginRepositoryPassword = null
boolean captureFileFingerprints = false
String develocityPluginVersion
TestConfig(String develocityPluginVersion) {
this.develocityPluginVersion = develocityPluginVersion
}
TestConfig withCCUDPlugin(String version = CCUD_PLUGIN_VERSION) {
ccudPluginVersion = version
@ -437,11 +534,13 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def getEnvVars() {
Map<String, String> envVars = [
DEVELOCITY_INJECTION_ENABLED: "true",
DEVELOCITY_URL: serverUrl,
DEVELOCITY_ALLOW_UNTRUSTED_SERVER: "true",
DEVELOCITY_PLUGIN_VERSION: DEVELOCITY_PLUGIN_VERSION,
DEVELOCITY_BUILD_SCAN_UPLOAD_IN_BACKGROUND: "true" // Need to upload in background since our Mock server doesn't cope with foreground upload
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME : "gradle-actions.inject-develocity.init.gradle",
DEVELOCITY_INJECTION_ENABLED : "true",
DEVELOCITY_URL : serverUrl,
DEVELOCITY_ALLOW_UNTRUSTED_SERVER : "true",
DEVELOCITY_PLUGIN_VERSION : develocityPluginVersion,
DEVELOCITY_BUILD_SCAN_UPLOAD_IN_BACKGROUND: "true", // Need to upload in background since our Mock server doesn't cope with foreground upload
DEVELOCITY_AUTO_INJECTION_CUSTOM_VALUE : 'gradle-actions'
]
if (enforceUrl) envVars.put("DEVELOCITY_ENFORCE_URL", "true")
if (ccudPluginVersion != null) envVars.put("DEVELOCITY_CCUD_PLUGIN_VERSION", ccudPluginVersion)
@ -455,11 +554,13 @@ class TestDevelocityInjection extends BaseInitScriptTest {
def getJvmArgs() {
List<String> jvmArgs = [
"-Ddevelocity.injection.init-script-name=gradle-actions.inject-develocity.init.gradle",
"-Ddevelocity.injection-enabled=true",
"-Ddevelocity.url=$serverUrl",
"-Ddevelocity.allow-untrusted-server=true",
"-Ddevelocity.plugin.version=$DEVELOCITY_PLUGIN_VERSION",
"-Ddevelocity.build-scan.upload-in-background=true"
"-Ddevelocity.plugin.version=$develocityPluginVersion",
"-Ddevelocity.build-scan.upload-in-background=true",
"-Ddevelocity.auto-injection.custom-value=gradle-actions"
]
if (enforceUrl) jvmArgs.add("-Ddevelocity.enforce-url=true")