Skip to content

Commit fa2879f

Browse files
committed
Introduce build conventions to reduce repetition in build.gradle files
1 parent c8c04b4 commit fa2879f

File tree

10 files changed

+256
-214
lines changed

10 files changed

+256
-214
lines changed
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,25 @@
11
plugins {
2-
id "checkstyle"
3-
id "io.spring.javaformat" version "$javaFormatVersion"
2+
id "build-conventions"
43
id "java"
54
id "maven-publish"
65
}
76

87
description = "Gradle Enterprise Conventions Core"
9-
group = 'io.spring.ge.conventions'
10-
11-
sourceCompatibility = 1.8
12-
targetCompatibility = 1.8
138

149
repositories {
1510
mavenCentral()
1611
}
1712

1813
dependencies {
19-
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
20-
2114
testImplementation("org.assertj:assertj-core:3.24.2")
2215
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
2316
testImplementation("org.mockito:mockito-core:4.11.0")
2417
}
2518

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-
5619
publishing {
5720
publications {
5821
maven(MavenPublication) {
5922
from components.java
6023
}
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-
}
9024
}
9125
}
Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
plugins {
2-
id "checkstyle"
3-
id "io.spring.javaformat" version "$javaFormatVersion"
2+
id "build-conventions"
43
id "java-gradle-plugin"
54
id "maven-publish"
65
}
76

87
description = "Gradle Enterprise Conventions Gradle plugin"
9-
group = 'io.spring.ge.conventions'
10-
11-
sourceCompatibility = 1.8
12-
targetCompatibility = 1.8
138

149
repositories {
1510
mavenCentral()
1611
gradlePluginPortal()
1712
}
1813

1914
dependencies {
20-
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
21-
2215
compileOnly("com.gradle:develocity-gradle-plugin:${gradleEnterprisePluginVersion}")
2316

2417
implementation(project(":gradle-enterprise-conventions-core"))
@@ -39,67 +32,3 @@ gradlePlugin {
3932
}
4033
}
4134
}
42-
43-
test {
44-
useJUnitPlatform()
45-
}
46-
47-
java {
48-
withJavadocJar()
49-
withSourcesJar()
50-
}
51-
52-
checkstyle {
53-
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
54-
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
55-
toolVersion = 9.3
56-
}
57-
58-
tasks.withType(GenerateModuleMetadata).all {
59-
enabled = false
60-
}
61-
62-
if (project.hasProperty("distributionRepository")) {
63-
publishing {
64-
repositories {
65-
maven {
66-
url = "${distributionRepository}"
67-
name = "deployment"
68-
}
69-
}
70-
}
71-
}
72-
73-
publishing {
74-
publications {
75-
withType(MavenPublication) { mavenPublication ->
76-
pom {
77-
name = project.description
78-
description = project.description
79-
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
80-
organization {
81-
name = 'Pivotal Software, Inc.'
82-
url = 'https://spring.io'
83-
}
84-
licenses {
85-
license {
86-
name = 'The Apache Software License, Version 2.0'
87-
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
88-
}
89-
}
90-
scm {
91-
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
92-
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
93-
}
94-
developers {
95-
developer {
96-
id = 'wilkinsona'
97-
name = 'Andy Wilkinson'
98-
99-
roles = ["Project lead"]
100-
}
101-
}
102-
}
103-
}
104-
}
105-
}
Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
plugins {
2-
id "checkstyle"
3-
id "io.spring.javaformat" version "$javaFormatVersion"
2+
id "build-conventions"
43
id "java"
54
id "maven-publish"
65
}
76

87
description = "Gradle Enterprise Conventions Maven extension"
9-
group = 'io.spring.ge.conventions'
10-
11-
sourceCompatibility = 1.8
12-
targetCompatibility = 1.8
138

149
repositories {
1510
mavenCentral()
1611
}
1712

1813
dependencies {
19-
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
20-
2114
compileOnly("org.apache.maven:maven-core:3.6.3")
2215
compileOnly("org.codehaus.plexus:plexus-component-annotations:1.7.1")
2316

@@ -29,77 +22,10 @@ dependencies {
2922
testImplementation("org.mockito:mockito-core:4.11.0")
3023
}
3124

32-
tasks.withType(Test) { testTask ->
33-
if (testTask.name.startsWith("compatibilityTest_")) {
34-
testTask.filter {
35-
includeTestsMatching "*IntegrationTests"
36-
}
37-
}
38-
}
39-
40-
test {
41-
useJUnitPlatform()
42-
}
43-
44-
java {
45-
withJavadocJar()
46-
withSourcesJar()
47-
}
48-
49-
checkstyle {
50-
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
51-
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
52-
toolVersion = 9.3
53-
}
54-
55-
tasks.withType(GenerateModuleMetadata).all {
56-
enabled = false
57-
}
58-
59-
if (project.hasProperty("distributionRepository")) {
60-
publishing {
61-
repositories {
62-
maven {
63-
url = "${distributionRepository}"
64-
name = "deployment"
65-
}
66-
}
67-
}
68-
}
69-
7025
publishing {
7126
publications {
7227
maven(MavenPublication) {
7328
from components.java
7429
}
75-
withType(MavenPublication) { mavenPublication ->
76-
pom {
77-
name = project.description
78-
description = project.description
79-
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
80-
organization {
81-
name = 'Pivotal Software, Inc.'
82-
url = 'https://spring.io'
83-
}
84-
licenses {
85-
license {
86-
name = 'The Apache Software License, Version 2.0'
87-
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
88-
}
89-
}
90-
scm {
91-
url = 'https://github.com/spring-io/gradle-enterprise-conventions'
92-
connection = 'scm:git:https://github.com/spring-io/gradle-enterprise-conventions'
93-
}
94-
developers {
95-
developer {
96-
id = 'wilkinsona'
97-
name = 'Andy Wilkinson'
98-
99-
roles = ["Project lead"]
100-
}
101-
}
102-
}
103-
}
10430
}
10531
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id "checkstyle"
3+
id "java-gradle-plugin"
4+
id "io.spring.javaformat" version "0.0.39"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
gradlePlugin {
12+
plugins {
13+
conventionsPlugin {
14+
id = "build-conventions"
15+
implementationClass = "io.spring.ge.conventions.build.BuildConventionsPlugin"
16+
}
17+
}
18+
}
19+
20+
sourceCompatibility = "1.8"
21+
targetCompatibility = "1.8"
22+
23+
dependencies {
24+
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.39")
25+
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.39")
26+
}
27+
28+
checkstyle {
29+
def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")}
30+
config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml")
31+
toolVersion = 9.3
32+
}

gradle/plugins/build-conventions/settings.gradle

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.ge.conventions.build;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
import org.gradle.api.plugins.JavaPlugin;
22+
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
23+
24+
public class BuildConventionsPlugin implements Plugin<Project> {
25+
26+
@Override
27+
public void apply(Project target) {
28+
target.getPlugins().withType(JavaPlugin.class, (plugin) -> new JavaConventions().apply(target));
29+
target.getPlugins().withType(MavenPublishPlugin.class, (plugin) -> new MavenPublishConventions().apply(target));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)