Skip to content

Commit 1d2b7b4

Browse files
committed
Modernize the build by introducing a conventions plugin
1 parent d07e330 commit 1d2b7b4

File tree

24 files changed

+560
-230
lines changed

24 files changed

+560
-230
lines changed

build.gradle

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
plugins {
22
id 'base'
3-
id 'io.spring.javaformat' version "$javaFormatVersion" apply false
4-
id 'io.spring.nohttp' version '0.0.11' apply false
53
id 'maven-publish'
4+
id 'org.springframework.restdocs.conventions'
65
}
76

87
allprojects {
@@ -23,105 +22,6 @@ allprojects {
2322
}
2423
}
2524

26-
apply plugin: "io.spring.nohttp"
27-
apply from: "${rootProject.projectDir}/gradle/publish-maven.gradle"
28-
29-
nohttp {
30-
source.exclude "buildSrc/.gradle/**"
31-
source.exclude "**/build/**"
32-
source.exclude "**/target/**"
33-
}
34-
35-
ext {
36-
javadocLinks = [
37-
"https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/javadoc-api/",
38-
"https://docs.jboss.org/hibernate/validator/9.0/api/",
39-
"https://jakarta.ee/specifications/bean-validation/3.1/apidocs/"
40-
] as String[]
41-
}
42-
43-
check {
44-
dependsOn checkstyleNohttp
45-
}
46-
47-
subprojects { subproject ->
48-
plugins.withType(JavaPlugin) {
49-
subproject.apply plugin: "io.spring.javaformat"
50-
subproject.apply plugin: "checkstyle"
51-
52-
java {
53-
sourceCompatibility = 17
54-
targetCompatibility = 17
55-
}
56-
57-
configurations {
58-
all {
59-
resolutionStrategy.cacheChangingModulesFor 0, "minutes"
60-
}
61-
internal {
62-
canBeConsumed = false
63-
canBeResolved = false
64-
}
65-
compileClasspath.extendsFrom(internal)
66-
runtimeClasspath.extendsFrom(internal)
67-
testCompileClasspath.extendsFrom(internal)
68-
testRuntimeClasspath.extendsFrom(internal)
69-
}
70-
71-
test {
72-
testLogging {
73-
exceptionFormat = "full"
74-
}
75-
}
76-
77-
tasks.withType(JavaCompile) {
78-
options.compilerArgs = [ "-Werror", "-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes", "-Xlint:varargs", "-Xlint:options" ]
79-
options.encoding = "UTF-8"
80-
}
81-
82-
tasks.withType(Test) {
83-
maxHeapSize = "1024M"
84-
}
85-
86-
checkstyle {
87-
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
88-
configProperties = [ "checkstyle.config.dir" : rootProject.file("config/checkstyle") ]
89-
toolVersion = "10.12.4"
90-
}
91-
92-
dependencies {
93-
checkstyle("com.puppycrawl.tools:checkstyle:${checkstyle.toolVersion}")
94-
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}")
95-
}
96-
97-
plugins.withType(MavenPublishPlugin) {
98-
javadoc {
99-
description = "Generates project-level javadoc for use in -javadoc jar"
100-
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
101-
options.author = true
102-
options.header = "Spring REST Docs $version"
103-
options.docTitle = "${options.header} API"
104-
options.links = javadocLinks
105-
options.addStringOption "-quiet"
106-
options.encoding = "UTF-8"
107-
options.source = "17"
108-
}
109-
110-
java {
111-
withJavadocJar()
112-
withSourcesJar()
113-
}
114-
}
115-
}
116-
plugins.withType(MavenPublishPlugin) {
117-
subproject.apply from: "${rootProject.projectDir}/gradle/publish-maven.gradle"
118-
}
119-
tasks.withType(GenerateModuleMetadata) {
120-
enabled = false
121-
}
122-
123-
}
124-
12525
task api (type: Javadoc) {
12626
group = "Documentation"
12727
description = "Generates aggregated Javadoc API documentation."
@@ -130,7 +30,6 @@ task api (type: Javadoc) {
13030
Set<Project> publishedProjects = rootProject.subprojects.findAll { it != project}
13131
.findAll { it.plugins.hasPlugin(JavaPlugin) && it.plugins.hasPlugin(MavenPublishPlugin) }
13232
.findAll { !excludedProjects.contains(it.name) }
133-
.findAll { !it.name.startsWith('spring-boot-starter') }
13433
dependsOn publishedProjects.javadoc
13534
source publishedProjects.javadoc.source
13635
classpath = project.files(publishedProjects.javadoc.classpath)

buildSrc/build.gradle

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id "org.asciidoctor.jvm.convert" version "4.0.4"
3-
id "java-library"
3+
id "org.springframework.restdocs.conventions"
4+
id "java"
45
}
56

67
configurations {
@@ -10,19 +11,16 @@ configurations {
1011
dependencies {
1112
asciidoctorExt("io.spring.asciidoctor.backends:spring-asciidoctor-backends:0.0.5")
1213

13-
internal(platform(project(":spring-restdocs-platform")))
14-
internal(enforcedPlatform("org.springframework:spring-framework-bom:$springFrameworkVersion"))
15-
1614
testImplementation(project(":spring-restdocs-mockmvc"))
1715
testImplementation(project(":spring-restdocs-restassured"))
1816
testImplementation(project(":spring-restdocs-webtestclient"))
1917
testImplementation("jakarta.servlet:jakarta.servlet-api")
2018
testImplementation("jakarta.validation:jakarta.validation-api")
2119
testImplementation("org.testng:testng:6.9.10")
22-
testImplementation("org.junit.jupiter:junit-jupiter-api")
23-
}
20+
testImplementation("org.junit.jupiter:junit-jupiter")
2421

25-
tasks.findByPath("artifactoryPublish")?.enabled = false
22+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
23+
}
2624

2725
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
2826
baseDirFollowsSourceDir()

gradle/plugins/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
plugins {
2+
id "io.spring.javaformat" apply false
3+
id "base"
4+
}
5+
6+
new File(rootDir.parentFile.parentFile, "gradle.properties").withInputStream {
7+
def properties = new Properties()
8+
properties.load(it)
9+
properties.each { key, value ->
10+
if (key.endsWith("Version")) {
11+
project.ext.set(key, value)
12+
}
13+
}
14+
}
15+
16+
subprojects {
17+
apply plugin: "io.spring.javaformat"
18+
apply plugin: "checkstyle"
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
checkstyle {
25+
toolVersion = "10.12.4"
26+
}
27+
28+
dependencies {
29+
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:$javaFormatVersion")
30+
checkstyle("com.puppycrawl.tools:checkstyle:${checkstyle.toolVersion}")
31+
}
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
<module name="com.puppycrawl.tools.checkstyle.Checker">
6+
<module name="io.spring.javaformat.checkstyle.SpringChecks" />
7+
</module>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id "java-gradle-plugin"
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
gradlePluginPortal()
8+
}
9+
10+
gradlePlugin {
11+
plugins {
12+
conventions {
13+
id = "org.springframework.restdocs.conventions"
14+
implementationClass = "org.springframework.restdocs.build.conventions.ConventionsPlugin"
15+
}
16+
}
17+
}
18+
19+
dependencies {
20+
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:$javaFormatVersion")
21+
implementation("io.spring.nohttp:nohttp-gradle:0.0.11")
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2014-present 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 org.springframework.restdocs.build.conventions;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
22+
/**
23+
* Base class for {@link Plugin} conventions.
24+
*
25+
* @param <T> the type of plugin to which the conventions apply
26+
* @author Andy Wilkinson
27+
*/
28+
abstract class Conventions<T extends Plugin<Project>> {
29+
30+
private final Project project;
31+
32+
private final Class<T> pluginType;
33+
34+
Conventions(Project project, Class<T> pluginType) {
35+
this.project = project;
36+
this.pluginType = pluginType;
37+
}
38+
39+
void apply() {
40+
this.project.getPlugins().withType(this.pluginType).all(this::apply);
41+
}
42+
43+
abstract void apply(T plugin);
44+
45+
protected Project getProject() {
46+
return this.project;
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2014-present 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 org.springframework.restdocs.build.conventions;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
22+
/**
23+
* A {@link Plugin} that applies the Spring REST Docs project's Gradle build conventions.
24+
*
25+
* @author Andy Wilkinson
26+
*/
27+
public class ConventionsPlugin implements Plugin<Project> {
28+
29+
@Override
30+
public void apply(Project project) {
31+
new JavaBasePluginConventions(project).apply();
32+
new MavenPublishPluginConventions(project).apply();
33+
new JavaTestFixturesPluginConventions(project).apply();
34+
new NoHttpConventions(project).apply();
35+
}
36+
37+
}

0 commit comments

Comments
 (0)