-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single build Gradle plugin and Maven extension convention sample
- Loading branch information
1 parent
0ad93f7
commit d27b9e0
Showing
42 changed files
with
2,232 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.github/workflows/convention-develocity-shared-verification.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
name: Verify Convention Develocity Shared | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: [ 'convention-develocity-shared/**' ] | ||
pull_request: | ||
branches: [ main ] | ||
paths: [ 'convention-develocity-shared/**' ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build Convention Develocity Shared | ||
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 | ||
working-directory: convention-develocity-shared | ||
run: ./gradlew build publishToMavenLocal | ||
- name: Upload plugin | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: convention-develocity-shared | ||
path: ~/.m2/repository/com/myorg | ||
|
||
verification_gradle: | ||
name: Verify Example Build for Gradle ${{ matrix.versions.version }} | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
versions: | ||
- sample: '5' | ||
version: '5.0' | ||
- sample: '6' | ||
version: '6.0.1' | ||
- sample: '6.9_and_later' | ||
version: '6.9.4' | ||
- sample: '6.9_and_later' | ||
version: '7.0.2' | ||
- sample: '6.9_and_later' | ||
version: '8.0.2' | ||
- sample: '6.9_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-shared | ||
path: ~/.m2/repository/com/myorg | ||
- name: Set Gradle version | ||
if: ${{ matrix.versions.version != '(Current)' }} | ||
working-directory: convention-develocity-shared/examples/gradle_${{ matrix.versions.sample }} | ||
run: | | ||
sed -i '/distributionSha256Sum.*/d' gradle/wrapper/gradle-wrapper.properties | ||
./gradlew wrapper --gradle-version=${{ matrix.versions.version }} --no-scan | ||
./gradlew wrapper --gradle-version=${{ matrix.versions.version }} --no-scan | ||
- name: Verify example build | ||
id: build | ||
working-directory: convention-develocity-shared/examples/gradle_${{ matrix.versions.sample }} | ||
run: ./gradlew build -Ddevelocity.url=https://ge.solutions-team.gradle.com | ||
env: | ||
DEVELOCITY_ACCESS_KEY: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }} | ||
- name: Verify Build Scan published | ||
if: ${{ !steps.build.outputs.build-scan-url }} | ||
run: echo "::error ::No Build Scan published"; exit 1 | ||
|
||
verification: | ||
name: Verify Example Build for Maven ${{ matrix.versions.version }} | ||
needs: [build] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
versions: | ||
- sample: '3' | ||
version: '3.6.3' | ||
- sample: '3' | ||
version: '3.8.8' | ||
- sample: '3' | ||
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' | ||
cache: maven | ||
- name: Download extension | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: convention-develocity-maven-extension | ||
path: ~/.m2/repository/com/myorg | ||
- name: Set Maven version | ||
if: ${{ matrix.versions.version != '(Current)' }} | ||
working-directory: convention-develocity-shared/examples/maven_${{ matrix.versions.sample }} | ||
run: ./mvnw wrapper:wrapper -Dmaven=${{ matrix.versions.version }} -Ddevelocity.scan.disabled | ||
- name: Verify example build | ||
working-directory: convention-develocity-shared/examples/maven_${{ matrix.versions.sample }} | ||
run: ./mvnw clean verify -Ddevelocity.url=https://ge.solutions-team.gradle.com | ||
env: | ||
DEVELOCITY_ACCESS_KEY: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Convention Develocity Shared | ||
|
||
[//]: # (todo) |
37 changes: 37 additions & 0 deletions
37
convention-develocity-shared/convention-develocity-gradle-plugin/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
id("java-gradle-plugin") | ||
id("maven-publish") | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation("com.gradle:develocity-gradle-plugin:3.17.6") | ||
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.0.2") | ||
implementation(project(":convention-develocity-shared")) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(8) | ||
} | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
create("develocityConventions") { | ||
// CHANGE ME: change for your organization | ||
id = "com.myorg.convention-develocity-gradle-plugin" | ||
displayName = "Convention Develocity Gradle Plugin" | ||
description = "A Gradle plugin to apply and configure the Develocity Gradle plugin for com.myorg" | ||
implementationClass = "com.myorg.ConventionDevelocityGradlePlugin" | ||
} | ||
} | ||
} | ||
|
||
tasks.withType<ValidatePlugins>().configureEach { | ||
failOnWarning = true | ||
enableStricterValidation = true | ||
} |
66 changes: 66 additions & 0 deletions
66
...on-develocity-gradle-plugin/src/main/java/com/myorg/ConventionDevelocityGradlePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.myorg; | ||
|
||
import com.gradle.CommonCustomUserDataGradlePlugin; | ||
import com.gradle.develocity.agent.gradle.DevelocityConfiguration; | ||
import com.gradle.develocity.agent.gradle.DevelocityPlugin; | ||
import com.myorg.configurable.GradleDevelocityConfigurable; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.initialization.Settings; | ||
import org.gradle.util.GradleVersion; | ||
|
||
/** | ||
* An example Gradle plugin for enabling and configuring Develocity features | ||
*/ | ||
final class ConventionDevelocityGradlePlugin implements Plugin<Object> { | ||
|
||
@Override | ||
public void apply(Object target) { | ||
if (target instanceof Settings) { | ||
if (!isGradle6OrNewer()) { | ||
throw new GradleException("For Gradle versions prior to 6.0, the Convention Develocity plugin must be applied to the Root project"); | ||
} | ||
configureGradle6OrNewer((Settings) target); | ||
} else if (target instanceof 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"); | ||
} | ||
} | ||
} | ||
|
||
private void configureGradle6OrNewer(Settings settings) { | ||
settings.getPluginManager().apply(DevelocityPlugin.class); | ||
settings.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class); | ||
|
||
DevelocityConventions develocityConventions = new DevelocityConventions(); | ||
develocityConventions.configureDevelocity(new GradleDevelocityConfigurable(settings.getExtensions().getByType(DevelocityConfiguration.class))); | ||
// todo develocityConventions.configureBuildCache(...); | ||
} | ||
|
||
private void configureGradle5(Project project) { | ||
project.getPluginManager().apply(DevelocityPlugin.class); | ||
project.getPluginManager().apply(CommonCustomUserDataGradlePlugin.class); | ||
|
||
DevelocityConventions develocityConventions = new DevelocityConventions(); | ||
develocityConventions.configureDevelocity(new GradleDevelocityConfigurable(project.getExtensions().getByType(DevelocityConfiguration.class))); | ||
// configureBuildCache is not called because the build cache cannot be configured via a plugin prior to Gradle 6.0 | ||
} | ||
|
||
private static boolean isGradle6OrNewer() { | ||
return GradleVersion.current().compareTo(GradleVersion.version("6.0")) >= 0; | ||
} | ||
|
||
private static boolean isGradle5OrNewer() { | ||
return GradleVersion.current().compareTo(GradleVersion.version("5.0")) >= 0; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...city-gradle-plugin/src/main/java/com/myorg/configurable/GradleDevelocityConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.myorg.configurable; | ||
|
||
import com.gradle.develocity.agent.gradle.DevelocityConfiguration; | ||
|
||
public final class GradleDevelocityConfigurable implements DevelocityConfigurable { | ||
|
||
private final DevelocityConfiguration develocity; | ||
|
||
public GradleDevelocityConfigurable(DevelocityConfiguration develocity) { | ||
this.develocity = develocity; | ||
} | ||
|
||
@Override | ||
public void setServer(String server) { | ||
develocity.getServer().set(server); | ||
} | ||
|
||
@Override | ||
public void setProjectId(String projectId) { | ||
develocity.getProjectId().set(projectId); | ||
} | ||
|
||
@Override | ||
public void setAllowUntrustedServer(boolean allowUntrustedServer) { | ||
develocity.getAllowUntrustedServer().set(allowUntrustedServer); | ||
} | ||
|
||
@Override | ||
public void setAccessKey(String accessKey) { | ||
develocity.getAccessKey().set(accessKey); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
convention-develocity-shared/convention-develocity-maven-extension/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
plugins { | ||
id("java") | ||
id("maven-publish") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compileOnly("org.apache.maven:maven-core:3.9.8") | ||
compileOnly("org.codehaus.plexus:plexus-component-annotations:2.2.0") | ||
|
||
implementation("com.gradle:develocity-maven-extension:1.21.5") | ||
implementation("com.gradle:common-custom-user-data-maven-extension:2.0") | ||
implementation(project(":convention-develocity-shared")) | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(8) | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
from(components["java"]) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...y-maven-extension/src/main/java/com/myorg/ConventionDevelocityMavenExtensionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.myorg; | ||
|
||
import com.gradle.develocity.agent.maven.api.DevelocityApi; | ||
import com.gradle.develocity.agent.maven.api.DevelocityListener; | ||
import com.myorg.configurable.MavenDevelocityConfigurable; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
|
||
/** | ||
* An example Maven extension for enabling and configuring Develocity features. | ||
*/ | ||
@Component( | ||
role = DevelocityListener.class, | ||
hint = "convention-develocity-maven-extension", | ||
description = "Configures the Develocity Maven extension for com.myorg" | ||
) | ||
public final class ConventionDevelocityMavenExtensionListener implements DevelocityListener { | ||
|
||
@Override | ||
public void configure(DevelocityApi develocity, MavenSession session) { | ||
DevelocityConventions develocityConventions = new DevelocityConventions(); | ||
develocityConventions.configureDevelocity(new MavenDevelocityConfigurable(develocity)); | ||
// todo develocityConventions.configureBuildCache(...); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ity-maven-extension/src/main/java/com/myorg/configurable/MavenDevelocityConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.myorg.configurable; | ||
|
||
import com.gradle.develocity.agent.maven.api.DevelocityApi; | ||
|
||
public final class MavenDevelocityConfigurable implements DevelocityConfigurable { | ||
|
||
private final DevelocityApi develocity; | ||
|
||
public MavenDevelocityConfigurable(DevelocityApi develocity) { | ||
this.develocity = develocity; | ||
} | ||
|
||
@Override | ||
public void setServer(String server) { | ||
develocity.setServer(server); | ||
} | ||
|
||
@Override | ||
public void setProjectId(String projectId) { | ||
develocity.setProjectId(projectId); | ||
} | ||
|
||
@Override | ||
public void setAllowUntrustedServer(boolean allowUntrustedServer) { | ||
develocity.setAllowUntrustedServer(allowUntrustedServer); | ||
} | ||
|
||
@Override | ||
public void setAccessKey(String accessKey) { | ||
develocity.setAccessKey(accessKey); | ||
} | ||
|
||
} |
Oops, something went wrong.