Skip to content

Commit

Permalink
Configure Develocity Gradle plugin in Convention Gradle plugin
Browse files Browse the repository at this point in the history
* Update Convention Develocity Gradle plugin to use Develocity Gradle plugin

* Add verification workflow for Convention Develocity Gradle plugin

* Fail workflow if no Build Scan published

* Change example folder names

* Add build for Gradle 2 through 4

* Test more Gradle versions

* Run wrapper command twice

* Align Gradle 5 wrapper with tested version
  • Loading branch information
erichaagdev authored Jun 20, 2024
1 parent ab67be2 commit 927a74c
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Verify Convention Develocity Gradle Plugin

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
name: Build Convention Develocity Gradle Plugin
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle - Gradle 2 through 4
working-directory: convention-develocity-gradle-plugin/plugins/gradle-2-through-4
run: ./gradlew build
- name: Build with Gradle - Gradle 5 or newer
working-directory: convention-develocity-gradle-plugin/plugins/gradle-5-or-newer
run: ./gradlew build publishToMavenLocal
- name: Upload plugin
uses: actions/upload-artifact@v4
with:
name: convention-develocity-gradle-plugin
path: ~/.m2/repository/com/myorg

verification:
name: Verify Example Build for Gradle ${{ matrix.versions.version }}
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Gradle 3 and earlier is not tested because it does not apply CCUD and overriding the server URL is not possible.
# Gradle 4 is not tested because it does not support publishing to authenticated servers.
versions:
- sample: '5'
version: '5.0'
- sample: '6_and_later'
version: '6.0.1'
- sample: '6_and_later'
version: '7.0.2'
- sample: '6_and_later'
version: '8.0.2'
- sample: '6_and_later'
version: '(Current)'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Download plugin
uses: actions/download-artifact@v4
with:
name: convention-develocity-gradle-plugin
path: ~/.m2/repository/com/myorg
- name: Set Gradle version
if: ${{ matrix.versions.version != '(Current)' }}
working-directory: convention-develocity-gradle-plugin/examples/gradle_${{ matrix.versions.sample }}
run: |
./gradlew wrapper --gradle-version=${{ matrix.versions.version }}
./gradlew wrapper --gradle-version=${{ matrix.versions.version }}
env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.GE_SOLUTIONS_ACCESS_TOKEN }}
- name: Verify example build
id: build
working-directory: convention-develocity-gradle-plugin/examples/gradle_${{ matrix.versions.sample }}
run: ./gradlew build -Ddevelocity.url=https://ge.solutions-team.gradle.com
env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.GE_SOLUTIONS_ACCESS_TOKEN }}
- name: Verify Build Scan published
if: ${{ !steps.build.outputs.build-scan-url }}
run: echo "::error ::No Build Scan published"; exit 1
14 changes: 7 additions & 7 deletions convention-develocity-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ This project is structured as follows:
* `gradle-2-through-4` - Applies and configures the Build Scan plugin on builds using Gradle 2.0 through Gradle 4.10.3
* `gradle-5-or-newer` - Applies and configures the Develocity plugin on builds using Gradle 5.0 or higher
* `examples` - Contains example builds that apply the convention plugin for different Gradle versions
* `gradle_2.0` - Applies the convention plugin on a Gradle 2.0 build (only the Develocity plugin is applied)
* `gradle_4.1` - Applies the convention plugin on a Gradle 4.1 build (the Develocity and CCUD plugins are applied)
* `gradle_5.1.1` - Applies the convention plugin on a Gradle 5 build (the Develocity and CCUD plugins are applied)
* `gradle_6.0.1` - Applies the convention plugin on a Gradle 6+ build (the Develocity and CCUD plugins are applied)
* `gradle_3_and_earlier` - Applies the convention plugin on a Gradle 3 and earlier (only the Develocity plugin is applied)
* `gradle_4` - Applies the convention plugin on a Gradle 4 build (the Develocity and CCUD plugins are applied)
* `gradle_5` - Applies the convention plugin on a Gradle 5 build (the Develocity and CCUD plugins are applied)
* `gradle_6_and_later` - Applies the convention plugin on a Gradle 6 and later build (the Develocity and CCUD plugins are applied)

### Running the example builds

Expand All @@ -32,14 +32,14 @@ cd plugins/gradle-5-or-newer
Once you have published the plugins, you can run the four example builds under `examples`:

```bash
cd examples/gradle_6.0.1
cd examples/gradle_6_and_later
./gradlew build
```

Note that you would publish your convention plugins to your internal artifact provider, e.g., Artifactory or Nexus, for production usage.

#### Requirements

To run the Gradle 2.0 example build, use Java 8. To run the Gradle 4.1 example build, use Java 8 or 9. These builds will fail when used with newer versions of Java.
To run the Gradle 3 and earlier example build, use Java 8. To run the Gradle 4 example build, use Java 8 or 9. These builds will fail when used with newer versions of Java.

To run the Gradle 5.1.1 and Gradle 6.0.1 example builds, use Java 8 or higher.
To run the Gradle 5 and later example builds, use Java 8 or higher.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -44,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -125,8 +109,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

dependencies {
implementation 'com.gradle:gradle-enterprise-gradle-plugin:3.17.5'
implementation 'com.gradle:develocity-gradle-plugin:3.17.5'
implementation 'com.gradle:common-custom-user-data-gradle-plugin:2.0.2'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.myorg;

import com.gradle.CommonCustomUserDataGradlePlugin;
import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension;
import com.gradle.enterprise.gradleplugin.GradleEnterprisePlugin;
import com.gradle.scan.plugin.BuildScanExtension;
import com.gradle.scan.plugin.BuildScanPlugin;
import com.gradle.develocity.agent.gradle.DevelocityConfiguration;
import com.gradle.develocity.agent.gradle.DevelocityPlugin;
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration;
import org.gradle.StartParameter;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
Expand All @@ -27,14 +26,13 @@ public void apply(Object target) {
}
configureGradle6OrNewer((Settings) target);
} else if (target instanceof Project) {
Project project = (Project) target;
if (!project.equals(project.getRootProject())) {
throw new GradleException("The Convention Gradle Enterprise plugin may only be applied to the Root project");
}

if (isGradle6OrNewer()) {
throw new GradleException("For Gradle versions 6.0 and newer, the Convention Develocity plugin must be applied to Settings");
} else if (isGradle5OrNewer()) {
Project project = (Project) target;
if (!project.equals(project.getRootProject())) {
throw new GradleException("For Gradle versions prior to 6.0, the Convention Develocity plugin must be applied to the Root project");
}
configureGradle5(project);
} else {
throw new GradleException("For Gradle versions prior to 5.0, the Convention Develocity plugin is not supported");
Expand All @@ -43,24 +41,24 @@ public void apply(Object target) {
}

private void configureGradle6OrNewer(Settings settings) {
settings.getPluginManager().apply(GradleEnterprisePlugin.class);
settings.getPluginManager().apply(DevelocityPlugin.class);
settings.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class);
configureGradleEnterprise(settings.getExtensions().getByType(GradleEnterpriseExtension.class), settings.getGradle().getStartParameter());
configureBuildCache(settings.getBuildCache(), settings.getExtensions().getByType(GradleEnterpriseExtension.class));
configureDevelocity(settings.getExtensions().getByType(DevelocityConfiguration.class), settings.getGradle().getStartParameter());
configureBuildCache(settings.getBuildCache(), settings.getExtensions().getByType(DevelocityConfiguration.class));
}

private void configureGradle5(Project project) {
project.getPluginManager().apply(BuildScanPlugin.class);
project.getPluginManager().apply(DevelocityPlugin.class);
project.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class);
configureGradleEnterprise(project.getExtensions().getByType(GradleEnterpriseExtension.class), project.getGradle().getStartParameter());
configureDevelocity(project.getExtensions().getByType(DevelocityConfiguration.class), project.getGradle().getStartParameter());
// configureBuildCache is not called because the build cache cannot be configured via a plugin prior to Gradle 6.0
}

private void configureGradleEnterprise(GradleEnterpriseExtension gradleEnterprise, StartParameter startParameter) {
private void configureDevelocity(DevelocityConfiguration develocity, StartParameter startParameter) {
// CHANGE ME: Apply your Develocity configuration here
gradleEnterprise.setServer("https://develocity-samples.gradle.com");
develocity.getServer().set("https://develocity-samples.gradle.com");
if (!containsPropertiesTask(startParameter)) {
configureBuildScan(gradleEnterprise.getBuildScan());
configureBuildScan(develocity.getBuildScan());
}
}

Expand All @@ -69,15 +67,14 @@ private boolean containsPropertiesTask(StartParameter startParameter) {
|| startParameter.getTaskNames().stream().anyMatch(it -> it.endsWith(":properties"));
}

private void configureBuildScan(BuildScanExtension buildScan) {
private void configureBuildScan(BuildScanConfiguration buildScan) {
// CHANGE ME: Apply your Build Scan configuration here
buildScan.publishAlways();
buildScan.setUploadInBackground(!isCi());
buildScan.getUploadInBackground().set(!isCi());
}

private void configureBuildCache(BuildCacheConfiguration buildCache, GradleEnterpriseExtension gradleEnterprise) {
private void configureBuildCache(BuildCacheConfiguration buildCache, DevelocityConfiguration develocity) {
// CHANGE ME: Apply your Build Cache configuration here
buildCache.remote(gradleEnterprise.getBuildCache(), remote -> {
buildCache.remote(develocity.getBuildCache(), remote -> {
remote.setEnabled(true);
remote.setPush(isCi());
});
Expand Down

0 comments on commit 927a74c

Please sign in to comment.