Skip to content

Commit 6ab5740

Browse files
committed
Refactor and simplify Spring Build Conventions Gradle Plugins.
* Declare CHECKSTYLE_VERSION class member constant in the CheckstylePlugin. * Remove the PlublishLocalPlugin. * Replace use of the deprecated JavaPluginConvention with JavaPluginExtension in the JavadocApiPlugin. * Replace the EclipseWtpPlugin with the EclipsePlugin applied in the AbstractSpringJavaPlugin class. * Review and fix spelling error in CopyPropertiesPlugin Javadoc. * Review, refactor and polish the Spring Gradle PropDepsPlugins including PropDepsPlugins for IntelliJ IDEA and Eclipse.
1 parent 75c8e06 commit 6ab5740

29 files changed

+207
-216
lines changed

buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.gradle.api.Project
2020
import org.gradle.api.plugins.GroovyPlugin
2121
import org.gradle.api.plugins.JavaPlugin
2222
import org.gradle.api.plugins.PluginManager
23-
import org.gradle.plugins.ide.eclipse.EclipseWtpPlugin
23+
import org.gradle.plugins.ide.eclipse.EclipsePlugin
2424
import org.gradle.plugins.ide.idea.IdeaPlugin
2525
import org.springframework.gradle.CopyPropertiesPlugin
2626
import org.springframework.gradle.propdeps.PropDepsEclipsePlugin
@@ -78,7 +78,7 @@ abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
7878
@SuppressWarnings("all")
7979
private void applyIdePlugins(PluginManager pluginManager) {
8080

81-
pluginManager.apply(EclipseWtpPlugin)
81+
pluginManager.apply(EclipsePlugin)
8282
pluginManager.apply(IdeaPlugin)
8383
}
8484

@@ -90,17 +90,18 @@ abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
9090
@SuppressWarnings("all")
9191
private void applySpringPlugins(PluginManager pluginManager) {
9292

93+
pluginManager.apply(ManagementConfigurationPlugin)
94+
pluginManager.apply(RepositoryConventionPlugin)
9395
pluginManager.apply(PropDepsPlugin)
9496
pluginManager.apply(PropDepsEclipsePlugin)
9597
pluginManager.apply(PropDepsIdeaPlugin)
96-
pluginManager.apply("io.spring.convention.springdependencymangement")
97-
pluginManager.apply("io.spring.convention.dependency-set")
98-
pluginManager.apply("io.spring.convention.repository")
99-
pluginManager.apply("io.spring.convention.javadoc-options")
100-
pluginManager.apply("io.spring.convention.tests-configuration")
101-
pluginManager.apply("io.spring.convention.integration-test")
102-
pluginManager.apply("io.spring.convention.jacoco");
103-
pluginManager.apply("io.spring.convention.checkstyle")
98+
pluginManager.apply(SpringDependencyManagementConventionPlugin)
99+
pluginManager.apply(DependencySetPlugin)
100+
pluginManager.apply(TestsConfigurationPlugin)
101+
pluginManager.apply(IntegrationTestPlugin)
102+
pluginManager.apply(JacocoPlugin);
103+
pluginManager.apply(JavadocOptionsPlugin)
104+
pluginManager.apply(CheckstylePlugin)
104105
pluginManager.apply(CopyPropertiesPlugin)
105106
}
106107

buildSrc/src/main/groovy/io/spring/gradle/convention/ArtifactoryPlugin.groovy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import org.gradle.api.Plugin
1919
import org.gradle.api.Project
2020

2121
/**
22-
* Applies the JFrag Artifactory Gradle {@link Plugin} to publish Gradle {@link Project} artifacts to
23-
* the Spring Artifactory Repositories.
22+
* Applies and configures the JFrag Artifactory Gradle {@link Plugin} to publish Gradle {@link Project} artifacts
23+
* to the Spring {@literal snapshot}, {@literal milestone} and {@literal release} repositories in Artifactory.
2424
*
2525
* @author Rob Winch
2626
* @author John Blum
@@ -39,7 +39,7 @@ class ArtifactoryPlugin implements Plugin<Project> {
3939
publish {
4040
repository {
4141
repoKey = resolveRepositoryKey(project)
42-
if (project.hasProperty('artifactoryUsername')) {
42+
if (isAuthRequired(project)) {
4343
username = artifactoryUsername
4444
password = artifactoryPassword
4545
}
@@ -52,6 +52,10 @@ class ArtifactoryPlugin implements Plugin<Project> {
5252
}
5353
}
5454

55+
private boolean isAuthRequired(Project project) {
56+
project.hasProperty('artifactoryUsername')
57+
}
58+
5559
private String resolveRepositoryKey(Project project) {
5660

5761
boolean isSnapshot = Utils.isSnapshot(project);

buildSrc/src/main/groovy/io/spring/gradle/convention/CheckstylePlugin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.gradle.api.plugins.JavaPlugin
3030
class CheckstylePlugin implements Plugin<Project> {
3131

3232
static final String CHECKSTYLE_PATHNAME = 'etc/checkstyle'
33+
static final String CHECKSTYLE_VERSION = '8.21'
3334

3435
@Override
3536
void apply(Project project) {
@@ -46,7 +47,7 @@ class CheckstylePlugin implements Plugin<Project> {
4647

4748
project.checkstyle {
4849
configDirectory = checkstyleDirectory
49-
toolVersion = '8.21'
50+
toolVersion = CHECKSTYLE_VERSION
5051
}
5152
}
5253
}

buildSrc/src/main/groovy/io/spring/gradle/convention/DeployDocsPlugin.groovy

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import org.gradle.api.Project
2424
*/
2525
class DeployDocsPlugin implements Plugin<Project> {
2626

27+
static final String DEFAULT_SPRING_DOCS_HOST = 'docs-ip.spring.io';
28+
2729
@Override
2830
void apply(Project project) {
2931

@@ -42,25 +44,26 @@ class DeployDocsPlugin implements Plugin<Project> {
4244

4345
host = project.hasProperty('deployDocsHost')
4446
? project.findProperty('deployDocsHost')
45-
: 'docs-ip.spring.io'
47+
: DEFAULT_SPRING_DOCS_HOST
4648

4749
user = project.findProperty('deployDocsSshUsername')
4850

4951
identity = project.hasProperty('deployDocsSshKeyPath')
5052
? project.file(project.findProperty('deployDocsSshKeyPath'))
5153
: project.hasProperty('deployDocsSshKey')
5254
? project.findProperty('deployDocsSshKey')
53-
: identity
55+
: null
5456

5557
passphrase = project.hasProperty('deployDocsSshPassphrase')
5658
? project.findProperty('deployDocsSshPassphrase')
57-
: passphrase
59+
: null
60+
5861
}
5962
}
6063

6164
project.task('deployDocs') {
62-
dependsOn 'docsZip'
63-
doFirst {
65+
dependsOn 'docs'
66+
doLast {
6467
project.ssh.run {
6568
session(project.remotes.docs) {
6669

@@ -71,18 +74,20 @@ class DeployDocsPlugin implements Plugin<Project> {
7174

7275
execute "mkdir -p $tempPath"
7376

74-
project.tasks.docsZip.outputs.each { o ->
75-
put from: o.files, into: tempPath
77+
project.tasks.docsZip.outputs.each { out ->
78+
put from: out.files, into: tempPath
7679
}
7780

7881
execute "unzip $tempPath*.zip -d $tempPath"
7982

80-
def extractPath = "/var/www/domains/spring.io/docs/htdocs/autorepo/docs/${name}/${version}/"
83+
def extractPath =
84+
"/var/www/domains/spring.io/docs/htdocs/autorepo/docs/${name}/${version}/"
8185

8286
execute "rm -rf $extractPath"
8387
execute "mkdir -p $extractPath"
8488
execute "mv $tempPath/docs/* $extractPath"
8589
execute "chmod -R g+w $extractPath"
90+
8691
}
8792
}
8893
}

buildSrc/src/main/groovy/io/spring/gradle/convention/DocsPlugin.groovy

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package io.spring.gradle.convention
1818
import org.gradle.api.Plugin
1919
import org.gradle.api.Project
2020
import org.gradle.api.Task
21+
import org.gradle.api.file.DuplicatesStrategy
2122
import org.gradle.api.plugins.PluginManager
2223
import org.gradle.api.tasks.bundling.Zip
2324

@@ -32,28 +33,28 @@ class DocsPlugin implements Plugin<Project> {
3233
@Override
3334
void apply(Project project) {
3435

35-
PluginManager pluginManager = project.getPluginManager();
36+
PluginManager pluginManager = project.getPluginManager()
3637

37-
pluginManager.apply("org.asciidoctor.jvm.convert");
38-
pluginManager.apply("org.asciidoctor.jvm.pdf");
39-
pluginManager.apply(AsciidoctorConventionPlugin);
40-
pluginManager.apply(DeployDocsPlugin);
41-
pluginManager.apply(JavadocApiPlugin);
38+
pluginManager.apply("org.asciidoctor.jvm.convert")
39+
pluginManager.apply("org.asciidoctor.jvm.pdf")
40+
pluginManager.apply(AsciidoctorConventionPlugin)
41+
pluginManager.apply(DeployDocsPlugin)
42+
pluginManager.apply(JavadocApiPlugin)
4243

4344
Task docsZip = project.tasks.create('docsZip', Zip) {
4445

4546
archiveBaseName = project.rootProject.name
4647
archiveClassifier = 'docs'
4748
group = 'Distribution'
48-
description = "Builds -${archiveClassifier} archive containing all Docs for deployment at docs.spring.io."
49+
description = "Builds -${archiveClassifier} archive containing all documenation for deployment to docs-ip.spring.io."
4950
dependsOn 'api', 'asciidoctor'
5051

5152
from(project.tasks.api.outputs) {
5253
into 'api'
5354
}
5455

5556
into 'docs'
56-
duplicatesStrategy 'exclude'
57+
duplicatesStrategy DuplicatesStrategy.EXCLUDE
5758
}
5859

5960
Task docs = project.tasks.create("docs") {
@@ -63,5 +64,6 @@ class DocsPlugin implements Plugin<Project> {
6364
}
6465

6566
project.tasks.assemble.dependsOn docs
67+
6668
}
6769
}

buildSrc/src/main/groovy/io/spring/gradle/convention/IntegrationTestPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class IntegrationTestPlugin implements Plugin<Project> {
126126
}
127127
}
128128

129+
@SuppressWarnings("all")
129130
private boolean isIntegrationTestSourceAvailable(Project project) {
130131
return project.file('src/integration-test/').exists()
131132
}

buildSrc/src/main/groovy/io/spring/gradle/convention/JavadocApiPlugin.groovy

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2022-present the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -15,21 +15,26 @@
1515
*/
1616
package io.spring.gradle.convention
1717

18-
import java.util.regex.Pattern
19-
20-
import org.gradle.api.Action
2118
import org.gradle.api.JavaVersion
2219
import org.gradle.api.Plugin
2320
import org.gradle.api.Project
24-
import org.gradle.api.plugins.JavaPluginConvention
21+
import org.gradle.api.plugins.JavaPluginExtension
2522
import org.gradle.api.tasks.SourceSet
2623
import org.gradle.api.tasks.javadoc.Javadoc
2724
import org.slf4j.Logger
2825
import org.slf4j.LoggerFactory
2926

27+
import java.util.regex.Pattern
28+
3029
/**
30+
* Generates Javadoc API documentation for {@literal this} {@link Project}.
31+
*
3132
* @author Rob Winch
3233
* @author John Blum
34+
* @see org.gradle.api.Plugin
35+
* @see org.gradle.api.Project
36+
* @see org.gradle.api.plugins.JavaPluginExtension
37+
* @see org.gradle.api.tasks.javadoc.Javadoc
3338
*/
3439
class JavadocApiPlugin implements Plugin<Project> {
3540

@@ -45,7 +50,7 @@ class JavadocApiPlugin implements Plugin<Project> {
4550
Javadoc api = project.tasks.create("api", Javadoc)
4651

4752
api.setGroup("Documentation")
48-
api.setDescription("Generates aggregated Javadoc API documentation.")
53+
api.setDescription("Generates Javadoc API documentation.")
4954
api.setDestinationDir(new File(project.getBuildDir(), "api"))
5055
api.setMaxMemory("1024m")
5156

@@ -80,26 +85,22 @@ class JavadocApiPlugin implements Plugin<Project> {
8085
excludes.each {this.excludes.add(Pattern.compile(it)) }
8186
}
8287

83-
private void addProject(Javadoc api, Project project) {
88+
private void addProject(Javadoc javadoc, Project project) {
8489

8590
if (isProjectIncluded(project)) {
8691

8792
logInfo("Add sources for project {}", project)
8893

89-
project.getPlugins().withType(SpringModulePlugin.class).all { plugin ->
94+
project.getPlugins().withType(SpringModulePlugin).all { plugin ->
9095

91-
JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class)
92-
SourceSet mainSourceSet = java.getSourceSets().getByName("main")
96+
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension)
9397

94-
api.setSource(api.getSource().plus(mainSourceSet.getAllJava()))
98+
SourceSet mainSourceSet = java.getSourceSets().getByName("main")
9599

96-
project.getTasks().withType(Javadoc.class).all(new Action<Javadoc>() {
100+
javadoc.setSource(javadoc.getSource() + mainSourceSet.getAllJava())
97101

98-
@Override
99-
void execute(Javadoc projectJavadoc) {
100-
api.setClasspath(api.getClasspath().plus(projectJavadoc.getClasspath()))
101-
}
102-
})
102+
project.getTasks().withType(Javadoc).all((Javadoc javadocTask) ->
103+
javadoc.setClasspath(javadoc.getClasspath() + javadocTask.getClasspath()))
103104
}
104105
}
105106
}

buildSrc/src/main/groovy/io/spring/gradle/convention/ManagementConfigurationPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Creates a {@literal Management} Gradle {@link Configuration} that is appropriate for adding a platform
34-
* so that it is not exposed externally.
34+
* that it is not exposed externally.
3535
*
3636
* If the {@link JavaPlugin} is applied, then the {@literal compileClasspath}, {@literal runtimeClasspath},
3737
* {@literal testCompileClasspath}, and {@literal testRuntimeClasspath} will extend from it.
@@ -73,9 +73,9 @@ public void apply(Project project) {
7373

7474
plugins.withType(MavenPublishPlugin.class, mavenPublishPlugin -> {
7575

76-
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
76+
PublishingExtension publishingExtension = project.getExtensions().getByType(PublishingExtension.class);
7777

78-
publishing.getPublications().withType(MavenPublication.class, mavenPublication ->
78+
publishingExtension.getPublications().withType(MavenPublication.class, mavenPublication ->
7979
mavenPublication.versionMapping(versions ->
8080
versions.allVariants(VariantVersionMappingStrategy::fromResolutionResult)));
8181
});

buildSrc/src/main/groovy/io/spring/gradle/convention/MavenBomPlugin.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class MavenBomPlugin implements Plugin<Project> {
5757
}
5858
}
5959

60-
// TODO: Why?
61-
Utils.configureDeployArtifactsTask(project)
62-
6360
// TODO: Shouldn't this be { archives project.mavenBom } according to:
6461
// https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getArtifacts--
6562
// TODO: Is this even necessary since this block is defined in MavenBomTask?

buildSrc/src/main/groovy/io/spring/gradle/convention/RootProjectPlugin.groovy

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package io.spring.gradle.convention
1818
import io.spring.nohttp.gradle.NoHttpPlugin
1919
import org.gradle.api.Plugin
2020
import org.gradle.api.Project
21+
import org.gradle.api.Task
2122
import org.gradle.api.plugins.BasePlugin
2223
import org.gradle.api.plugins.PluginManager
2324
import org.springframework.gradle.maven.SpringNexusPublishPlugin
@@ -47,19 +48,23 @@ class RootProjectPlugin implements Plugin<Project> {
4748
}
4849
}
4950

50-
// Add Maven Central Repository (resolution) to the list of repositories used by this build
51-
// to resolve dependencies.
51+
// Adds the Maven Central Repository to the list of repositories used by this build to resolve dependencies.
5252
project.repositories.mavenCentral()
5353

5454
configureSonarQube(project)
5555

5656
project.tasks.create("dependencyManagementExport", DependencyManagementExportTask)
5757

58-
def finalizeDeployArtifacts = project.task("finalizeDeployArtifacts")
58+
project.task("releasePublishedArtifacts", { Task releasePublishedArtifacts ->
59+
if (isReleasingToMavenCentral(project)) {
60+
releasePublishedArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository
61+
}
62+
})
63+
}
5964

60-
if (Utils.isRelease(project) && project.hasProperty("ossrhUsername")) {
61-
finalizeDeployArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository
62-
}
65+
@SuppressWarnings("all")
66+
private boolean isReleasingToMavenCentral(Project project) {
67+
Utils.isRelease(project) && project.hasProperty("ossrhUsername")
6368
}
6469

6570
@SuppressWarnings("all")

0 commit comments

Comments
 (0)