Skip to content

Commit 7ce1f5e

Browse files
committed
Configure Maven publications with Gradle
Prior to this commit, the build would use a custom task to create a BOM and manually include/exclude/customize dependencies. It would also use the "maven" plugin to customize the POM before publication. This commit now uses a Gradle Java Platform for publishing the Spring Framework BOM. We're also now using the "maven-publish" plugin to prepare and customize publications. This commit also tells the artifactory plugin (which is currently applied only on the CI) not to publish internal modules. See gh-23282
1 parent 0370101 commit 7ce1f5e

File tree

7 files changed

+82
-100
lines changed

7 files changed

+82
-100
lines changed

build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ext {
4545
}
4646
}
4747

48-
configure(allprojects.findAll { (it.name != "spring-framework-bom") } ) { project ->
48+
configure(allprojects.findAll { (it.name != "framework-bom") } ) { project ->
4949
group = "org.springframework"
5050

5151
apply plugin: "java"
@@ -177,6 +177,7 @@ configure(rootProject) {
177177
apply plugin: "kotlin"
178178
apply plugin: "io.spring.nohttp"
179179
apply plugin: 'org.springframework.build.api-diff'
180+
apply from: "${rootDir}/gradle/publications.gradle"
180181
apply from: "${rootDir}/gradle/docs.gradle"
181182

182183
nohttp {
@@ -200,10 +201,14 @@ configure(rootProject) {
200201
asciidoctor("io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.3.RELEASE")
201202
}
202203

203-
artifacts {
204-
archives docsZip
205-
archives schemaZip
206-
archives distZip
204+
publishing {
205+
publications {
206+
springFramework(MavenPublication) {
207+
artifact docsZip
208+
artifact schemaZip
209+
artifact distZip
210+
}
211+
}
207212
}
208213
}
209214

framework-bom/framework-bom.gradle

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,23 @@
11
description = "Spring Framework (Bill of Materials)"
22

3-
apply plugin: "java"
4-
apply plugin: "maven"
3+
apply plugin: 'java-platform'
4+
apply from: "$rootDir/gradle/publications.gradle"
55

6-
configurations.archives.artifacts.clear()
7-
artifacts {
8-
// work around GRADLE-2406 by attaching text artifact
9-
archives(file("spring-framework-bom.txt"))
10-
}
6+
group = "org.springframework"
117

12-
install {
13-
repositories.mavenInstaller {
14-
pom.whenConfigured {
15-
packaging = "pom"
16-
withXml {
17-
asNode().children().last() + {
18-
delegate.dependencyManagement {
19-
delegate.dependencies {
20-
parent.moduleProjects.sort { "$it.name" }.each { p ->
21-
if (p != project) {
22-
delegate.dependency {
23-
delegate.groupId(p.group)
24-
delegate.artifactId(p.name)
25-
delegate.version(p.version)
26-
}
27-
}
28-
}
29-
}
30-
}
31-
}
32-
}
8+
dependencies {
9+
constraints {
10+
parent.moduleProjects.sort { "$it.name" }.each {
11+
api it
3312
}
3413
}
3514
}
15+
16+
publishing {
17+
publications {
18+
springFramework(MavenPublication) {
19+
artifactId = 'spring-framework-bom'
20+
from components.javaPlatform
21+
}
22+
}
23+
}

framework-bom/spring-framework-bom.txt

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

gradle/publications.gradle

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apply plugin: "maven-publish"
2+
3+
publishing {
4+
publications {
5+
springFramework(MavenPublication) {
6+
pom {
7+
name = project.description
8+
description = project.description
9+
url = "https://github.com/spring-projects/spring-framework"
10+
organization {
11+
name = "Spring IO"
12+
url = "https://spring.io/projects/spring-framework"
13+
}
14+
licenses {
15+
license {
16+
name = "Apache License, Version 2.0"
17+
url = "https://www.apache.org/licenses/LICENSE-2.0"
18+
distribution = "repo"
19+
}
20+
}
21+
scm {
22+
url = "https://github.com/spring-projects/spring-framework"
23+
connection = "scm:git:git://github.com/spring-projects/spring-framework"
24+
developerConnection = "scm:git:git://github.com/spring-projects/spring-framework"
25+
}
26+
developers {
27+
developer {
28+
id = "jhoeller"
29+
name = "Juergen Hoeller"
30+
31+
}
32+
}
33+
issueManagement {
34+
system = "GitHub"
35+
url = "https://github.com/spring-projects/spring-framework/issues"
36+
}
37+
}
38+
}
39+
}
40+
}

gradle/spring-module.gradle

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'org.springframework.build.compile'
22
apply plugin: 'org.springframework.build.optional-dependencies'
33
apply plugin: 'org.springframework.build.test-sources'
4-
apply plugin: "maven"
4+
apply from: "$rootDir/gradle/publications.gradle"
55

66
jar {
77
manifest.attributes["Implementation-Title"] = project.name
@@ -47,66 +47,14 @@ task javadocJar(type: Jar) {
4747
from javadoc
4848
}
4949

50-
artifacts {
51-
archives sourcesJar
52-
archives javadocJar
53-
}
54-
55-
install {
56-
repositories.mavenInstaller {
57-
customizePom(pom, project)
50+
publishing {
51+
publications {
52+
springFramework(MavenPublication) {
53+
from components.java
54+
artifact sourcesJar
55+
artifact javadocJar
56+
}
5857
}
5958
}
6059

61-
def customizePom(pom, gradleProject) {
62-
pom.whenConfigured { generatedPom ->
63-
// eliminate test-scoped dependencies (no need in maven central poms)
64-
generatedPom.dependencies.removeAll { dep ->
65-
dep.scope == "test"
66-
}
67-
68-
// sort to make pom dependencies order consistent to ease comparison of older poms
69-
generatedPom.dependencies = generatedPom.dependencies.sort { dep ->
70-
"$dep.scope:$dep.groupId:$dep.artifactId"
71-
}
7260

73-
def managedVersions = dependencyManagement.managedVersions
74-
generatedPom.dependencies.findAll{dep -> !dep.version }.each { dep ->
75-
dep.version = managedVersions["${dep.groupId}:${dep.artifactId}"]
76-
}
77-
78-
// add all items necessary for maven central publication
79-
generatedPom.project {
80-
name = gradleProject.description
81-
description = gradleProject.description
82-
url = "https://github.com/spring-projects/spring-framework"
83-
organization {
84-
name = "Spring IO"
85-
url = "https://projects.spring.io/spring-framework"
86-
}
87-
licenses {
88-
license {
89-
name "Apache License, Version 2.0"
90-
url "https://www.apache.org/licenses/LICENSE-2.0"
91-
distribution "repo"
92-
}
93-
}
94-
scm {
95-
url = "https://github.com/spring-projects/spring-framework"
96-
connection = "scm:git:git://github.com/spring-projects/spring-framework"
97-
developerConnection = "scm:git:git://github.com/spring-projects/spring-framework"
98-
}
99-
developers {
100-
developer {
101-
id = "jhoeller"
102-
name = "Juergen Hoeller"
103-
104-
}
105-
}
106-
issueManagement {
107-
system = "GitHub"
108-
url = "https://github.com/spring-projects/spring-framework/issues"
109-
}
110-
}
111-
}
112-
}

integration-tests/integration-tests.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ dependencies {
1919
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
2020
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
2121
testCompile("org.hibernate:hibernate-core:5.1.17.Final")
22-
}
22+
}
23+
24+
// Avoid publishing JAR to the artifact repository
25+
if (pluginManager.hasPlugin("com.jfrog.artifactory")) {
26+
artifactoryPublish.skip = true
27+
}

spring-core/kotlin-coroutines/kotlin-coroutines.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ dependencies {
1010
compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
1111
}
1212

13-
// Avoid publishing coroutines JAR to the artifact repository
14-
if (pluginManager.hasPlugin("artifactoryPublish")) {
13+
// Avoid publishing JAR to the artifact repository
14+
if (pluginManager.hasPlugin("com.jfrog.artifactory")) {
1515
artifactoryPublish.skip = true
1616
}
1717

0 commit comments

Comments
 (0)