Skip to content

Commit c8c04b4

Browse files
committed
Reinstate Maven support
Closes gh-81
1 parent d6c72eb commit c8c04b4

File tree

42 files changed

+2323
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2323
-351
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gradle Enterprise Conventions
22

3-
Conventions for Gradle projects that use the Gradle Enterprise instance hosted at [ge.spring.io](https://ge.spring.io).
3+
Conventions for Maven and Gradle projects that use the Gradle Enterprise instance hosted at [ge.spring.io](https://ge.spring.io).
44

55
## Build cache conventions
66

@@ -26,7 +26,9 @@ When applied alongside the [Develocity Plugin](https://plugins.gradle.org/plugin
2626
The build scans will be customized to:
2727

2828
- Add tags:
29-
- `JDK-<version>`, where `<version>` is the value of the `toolchainVersion` project property or, when not set, the specification version of the JDK running the build.
29+
- `JDK-<version>`.
30+
When using Maven, `<version>` is the specification version of the JDK running the build.
31+
When using Gradle, `<version>` is the value of the `toolchainVersion` project property or, when not set, it's the specification version of the JDK running the build.
3032
- `CI` or `Local` depending on where the build is executing.
3133
- `dirty` if the git working copy is dirty.
3234
- Name of the git branch being built.
@@ -96,6 +98,8 @@ Jenkins is detected by looking for an environment variable named `JENKINS_URL`.
9698
Releases of the conventions are published to Maven Central.
9799
Snapshots are published to https://repo.spring.io/snapshot.
98100

101+
### Gradle
102+
99103
The first step in using the conventions is to make the necessary repository available for plugin resolution.
100104
This is done by configuring a plugin management repository in `settings.gradle`, as shown in the following example:
101105

@@ -120,3 +124,22 @@ plugins {
120124
// …
121125
}
122126
```
127+
128+
### Maven
129+
130+
To use the conventions, create a `.mvn/extensions.xml` file in the root of the project:
131+
132+
```xml
133+
<?xml version="1.0" encoding="UTF-8"?>
134+
<extensions>
135+
<extension>
136+
<groupId>io.spring.ge.conventions</groupId>
137+
<artifactId>gradle-enterprise-conventions-maven-extension</artifactId>
138+
<version><<version>></version>
139+
</extension>
140+
</extensions>
141+
```
142+
143+
Any existing `.mvn/gradle-enterprise.xml` file should be deleted in favor of the configuration that's provided by the conventions.
144+
Lastly, add `.mvn/.develocity/` to the project's `.gitignore` file.
145+
The conventions are ready to use.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
plugins {
2+
id "checkstyle"
3+
id "io.spring.javaformat" version "$javaFormatVersion"
4+
id "java"
5+
id "maven-publish"
6+
}
7+
8+
description = "Gradle Enterprise Conventions Core"
9+
group = 'io.spring.ge.conventions'
10+
11+
sourceCompatibility = 1.8
12+
targetCompatibility = 1.8
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
20+
21+
testImplementation("org.assertj:assertj-core:3.24.2")
22+
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
23+
testImplementation("org.mockito:mockito-core:4.11.0")
24+
}
25+
26+
test {
27+
useJUnitPlatform()
28+
}
29+
30+
java {
31+
withJavadocJar()
32+
withSourcesJar()
33+
}
34+
35+
checkstyle {
36+
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
37+
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
38+
toolVersion = 9.3
39+
}
40+
41+
tasks.withType(GenerateModuleMetadata).all {
42+
enabled = false
43+
}
44+
45+
if (project.hasProperty("distributionRepository")) {
46+
publishing {
47+
repositories {
48+
maven {
49+
url = "${distributionRepository}"
50+
name = "deployment"
51+
}
52+
}
53+
}
54+
}
55+
56+
publishing {
57+
publications {
58+
maven(MavenPublication) {
59+
from components.java
60+
}
61+
withType(MavenPublication) { mavenPublication ->
62+
pom {
63+
name = project.description
64+
description = project.description
65+
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
66+
organization {
67+
name = 'Pivotal Software, Inc.'
68+
url = 'https://spring.io'
69+
}
70+
licenses {
71+
license {
72+
name = 'The Apache Software License, Version 2.0'
73+
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
74+
}
75+
}
76+
scm {
77+
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
78+
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
79+
}
80+
developers {
81+
developer {
82+
id = 'wilkinsona'
83+
name = 'Andy Wilkinson'
84+
85+
roles = ["Project lead"]
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}

src/main/java/io/spring/ge/conventions/gradle/BuildCacheConventions.java renamed to gradle-enterprise-conventions-core/src/main/java/io/spring/ge/conventions/core/BuildCacheConventions.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.spring.ge.conventions.gradle;
17+
package io.spring.ge.conventions.core;
1818

1919
import java.util.Map;
2020

21-
import com.gradle.develocity.agent.gradle.buildcache.DevelocityBuildCache;
22-
import org.gradle.caching.configuration.BuildCacheConfiguration;
23-
2421
/**
2522
* Conventions that are applied to the build cache.
2623
*
@@ -30,25 +27,22 @@ public class BuildCacheConventions {
3027

3128
private final Map<String, String> env;
3229

33-
private final Class<? extends DevelocityBuildCache> buildCacheType;
34-
35-
public BuildCacheConventions(Class<? extends DevelocityBuildCache> buildCache) {
36-
this(buildCache, System.getenv());
30+
public BuildCacheConventions() {
31+
this(System.getenv());
3732
}
3833

39-
BuildCacheConventions(Class<? extends DevelocityBuildCache> buildCacheType, Map<String, String> env) {
34+
BuildCacheConventions(Map<String, String> env) {
4035
this.env = env;
41-
this.buildCacheType = buildCacheType;
4236
}
4337

4438
/**
4539
* Applies the conventions to the given {@code buildCache}.
4640
* @param buildCache build cache to be configured
4741
*/
48-
public void execute(BuildCacheConfiguration buildCache) {
49-
buildCache.local((local) -> local.setEnabled(true));
50-
buildCache.remote(this.buildCacheType, (remote) -> {
51-
remote.setEnabled(true);
42+
public void execute(ConfigurableBuildCache buildCache) {
43+
buildCache.local((local) -> local.enable());
44+
buildCache.remote((remote) -> {
45+
remote.enable();
5246
String cacheServer = this.env.get("DEVELOCITY_CACHE_SERVER");
5347
if (cacheServer == null) {
5448
cacheServer = serverOfCacheUrl(this.env.get("GRADLE_ENTERPRISE_CACHE_URL"));
@@ -62,7 +56,7 @@ public void execute(BuildCacheConfiguration buildCache) {
6256
accessKey = this.env.get("GRADLE_ENTERPRISE_ACCESS_KEY");
6357
}
6458
if (hasText(accessKey) && ContinuousIntegration.detect(this.env) != null) {
65-
remote.setPush(true);
59+
remote.enablePush();
6660
}
6761
});
6862
}

src/main/java/io/spring/ge/conventions/gradle/BuildScanConventions.java renamed to gradle-enterprise-conventions-core/src/main/java/io/spring/ge/conventions/core/BuildScanConventions.java

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package io.spring.ge.conventions.gradle;
17+
package io.spring.ge.conventions.core;
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.UnsupportedEncodingException;
@@ -23,93 +23,89 @@
2323
import java.util.function.Consumer;
2424
import java.util.stream.Collectors;
2525

26-
import com.gradle.develocity.agent.gradle.DevelocityConfiguration;
27-
import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration;
28-
import io.spring.ge.conventions.gradle.ProcessRunner.RunFailedException;
29-
import org.gradle.api.Action;
26+
import io.spring.ge.conventions.core.ProcessRunner.RunFailedException;
3027

3128
/**
32-
* {@link Action} that configures the {@link BuildScanConfiguration build scan} with
33-
* Spring conventions.
29+
* Conventions that are applied to build scans for Maven and Gradle builds. Spring
30+
* conventions.
3431
*
3532
* @author Andy Wilkinson
3633
*/
37-
class BuildScanConventions implements Action<BuildScanConfiguration> {
38-
39-
private final DevelocityConfiguration develocity;
34+
public class BuildScanConventions {
4035

4136
private final ProcessRunner processRunner;
4237

4338
private final Map<String, String> env;
4439

45-
BuildScanConventions(DevelocityConfiguration develocity, ProcessRunner processRunner) {
46-
this(develocity, processRunner, System.getenv());
40+
public BuildScanConventions(ProcessRunner processRunner) {
41+
this(processRunner, System.getenv());
4742
}
4843

49-
BuildScanConventions(DevelocityConfiguration develocity, ProcessRunner processRunner, Map<String, String> env) {
50-
this.develocity = develocity;
44+
protected BuildScanConventions(ProcessRunner processRunner, Map<String, String> env) {
5145
this.processRunner = processRunner;
5246
this.env = env;
5347
}
5448

5549
/**
56-
* Applies the conventions to the given {@code buildScan}.
50+
* Applies the conventions to the given {@code develocity} and {@code buildScan}.
51+
* @param develocity develocity to be configured
5752
* @param buildScan build scan to be configured
5853
*/
59-
@Override
60-
public void execute(BuildScanConfiguration buildScan) {
54+
public void execute(ConfigurableDevelocity develocity, ConfigurableBuildScan buildScan) {
6155
buildScan.obfuscation((obfuscation) -> obfuscation
6256
.ipAddresses((addresses) -> addresses.stream().map((address) -> "0.0.0.0").collect(Collectors.toList())));
63-
configurePublishing(buildScan);
57+
configurePublishing(develocity, buildScan);
6458
ContinuousIntegration ci = ContinuousIntegration.detect(this.env);
6559
tagBuildScan(buildScan, ci);
66-
buildScan.background(this::addGitMetadata);
60+
buildScan.background((backgrounded) -> addGitMetadata(develocity, backgrounded));
6761
buildScan.background(this::addDockerMetadata);
6862
buildScan.background(this::addDockerComposeMetadata);
6963
addCiMetadata(buildScan, ci);
70-
buildScan.getUploadInBackground().set(ci == null);
71-
buildScan.capture((settings) -> settings.getFileFingerprints().set(true));
64+
buildScan.uploadInBackground(ci == null);
65+
buildScan.captureInputFiles(true);
7266
}
7367

7468
/**
7569
* Configures publishing of the build scan. The default implementation always
7670
* publishes scans when authenticated and publishes them to
7771
* {@code https://ge.spring.io}.
72+
* @param develocity develocity to configure
7873
* @param buildScan build scan to configure
74+
*
7975
*/
80-
protected void configurePublishing(BuildScanConfiguration buildScan) {
81-
buildScan.publishing((publishing) -> publishing.onlyIf((context) -> context.isAuthenticated()));
82-
this.develocity.getServer().set("https://ge.spring.io");
76+
protected void configurePublishing(ConfigurableDevelocity develocity, ConfigurableBuildScan buildScan) {
77+
buildScan.publishIfAuthenticated();
78+
develocity.setServer("https://ge.spring.io");
8379
}
8480

85-
private void tagBuildScan(BuildScanConfiguration buildScan, ContinuousIntegration ci) {
81+
private void tagBuildScan(ConfigurableBuildScan buildScan, ContinuousIntegration ci) {
8682
tagCiOrLocal(buildScan, ci);
8783
tagJdk(buildScan);
8884
tagOperatingSystem(buildScan);
8985
}
9086

91-
private void tagCiOrLocal(BuildScanConfiguration buildScan, ContinuousIntegration ci) {
87+
private void tagCiOrLocal(ConfigurableBuildScan buildScan, ContinuousIntegration ci) {
9288
buildScan.tag((ci != null) ? "CI" : "Local");
9389
}
9490

95-
private void tagJdk(BuildScanConfiguration buildScan) {
91+
private void tagJdk(ConfigurableBuildScan buildScan) {
9692
buildScan.tag("JDK-" + getJdkVersion());
9793
}
9894

9995
protected String getJdkVersion() {
10096
return System.getProperty("java.specification.version");
10197
}
10298

103-
private void tagOperatingSystem(BuildScanConfiguration buildScan) {
99+
private void tagOperatingSystem(ConfigurableBuildScan buildScan) {
104100
buildScan.tag(System.getProperty("os.name"));
105101
}
106102

107-
private void addGitMetadata(BuildScanConfiguration buildScan) {
103+
private void addGitMetadata(ConfigurableDevelocity develocity, ConfigurableBuildScan buildScan) {
108104
run("git", "rev-parse", "--short=8", "--verify", "HEAD").standardOut((gitCommitId) -> {
109105
String commitIdLabel = "Git commit";
110106
buildScan.value(commitIdLabel, gitCommitId);
111107

112-
String server = this.develocity.getServer().getOrNull();
108+
String server = develocity.getServer();
113109
if (server != null) {
114110
buildScan.link("Git commit build scans", server + createSearchUrl(commitIdLabel, gitCommitId));
115111
}
@@ -124,16 +120,16 @@ private void addGitMetadata(BuildScanConfiguration buildScan) {
124120
});
125121
}
126122

127-
private void addDockerMetadata(BuildScanConfiguration buildScan) {
123+
private void addDockerMetadata(ConfigurableBuildScan buildScan) {
128124
run("docker", "--version").standardOut((dockerVersion) -> buildScan.value("Docker", dockerVersion));
129125
}
130126

131-
private void addDockerComposeMetadata(BuildScanConfiguration buildScan) {
127+
private void addDockerComposeMetadata(ConfigurableBuildScan buildScan) {
132128
run("docker", "compose", "version")
133129
.standardOut((dockerComposeVersion) -> buildScan.value("Docker Compose", dockerComposeVersion));
134130
}
135131

136-
private void addCiMetadata(BuildScanConfiguration buildScan, ContinuousIntegration ci) {
132+
private void addCiMetadata(ConfigurableBuildScan buildScan, ContinuousIntegration ci) {
137133
if (ci == null) {
138134
return;
139135
}

0 commit comments

Comments
 (0)