From 7ce1f5e652fee3f0e21925ac12f0882d733badb3 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 21 Aug 2019 15:24:03 +0200 Subject: [PATCH] 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 --- build.gradle | 15 ++-- framework-bom/framework-bom.gradle | 44 +++++------- framework-bom/spring-framework-bom.txt | 4 -- gradle/publications.gradle | 40 +++++++++++ gradle/spring-module.gradle | 68 +++---------------- integration-tests/integration-tests.gradle | 7 +- .../kotlin-coroutines.gradle | 4 +- 7 files changed, 82 insertions(+), 100 deletions(-) delete mode 100644 framework-bom/spring-framework-bom.txt create mode 100644 gradle/publications.gradle diff --git a/build.gradle b/build.gradle index e2cd92acf4ca..cf057c6e214c 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ ext { } } -configure(allprojects.findAll { (it.name != "spring-framework-bom") } ) { project -> +configure(allprojects.findAll { (it.name != "framework-bom") } ) { project -> group = "org.springframework" apply plugin: "java" @@ -177,6 +177,7 @@ configure(rootProject) { apply plugin: "kotlin" apply plugin: "io.spring.nohttp" apply plugin: 'org.springframework.build.api-diff' + apply from: "${rootDir}/gradle/publications.gradle" apply from: "${rootDir}/gradle/docs.gradle" nohttp { @@ -200,10 +201,14 @@ configure(rootProject) { asciidoctor("io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.3.RELEASE") } - artifacts { - archives docsZip - archives schemaZip - archives distZip + publishing { + publications { + springFramework(MavenPublication) { + artifact docsZip + artifact schemaZip + artifact distZip + } + } } } diff --git a/framework-bom/framework-bom.gradle b/framework-bom/framework-bom.gradle index d10dc256b1ae..259e3c5d670e 100644 --- a/framework-bom/framework-bom.gradle +++ b/framework-bom/framework-bom.gradle @@ -1,35 +1,23 @@ description = "Spring Framework (Bill of Materials)" -apply plugin: "java" -apply plugin: "maven" +apply plugin: 'java-platform' +apply from: "$rootDir/gradle/publications.gradle" -configurations.archives.artifacts.clear() -artifacts { - // work around GRADLE-2406 by attaching text artifact - archives(file("spring-framework-bom.txt")) -} +group = "org.springframework" -install { - repositories.mavenInstaller { - pom.whenConfigured { - packaging = "pom" - withXml { - asNode().children().last() + { - delegate.dependencyManagement { - delegate.dependencies { - parent.moduleProjects.sort { "$it.name" }.each { p -> - if (p != project) { - delegate.dependency { - delegate.groupId(p.group) - delegate.artifactId(p.name) - delegate.version(p.version) - } - } - } - } - } - } - } +dependencies { + constraints { + parent.moduleProjects.sort { "$it.name" }.each { + api it } } } + +publishing { + publications { + springFramework(MavenPublication) { + artifactId = 'spring-framework-bom' + from components.javaPlatform + } + } +} \ No newline at end of file diff --git a/framework-bom/spring-framework-bom.txt b/framework-bom/spring-framework-bom.txt deleted file mode 100644 index 919eb1796328..000000000000 --- a/framework-bom/spring-framework-bom.txt +++ /dev/null @@ -1,4 +0,0 @@ -This meta-project is used to generate a bill-of-materials POM that contains the other -projects in a dependencyManagement section. - - diff --git a/gradle/publications.gradle b/gradle/publications.gradle new file mode 100644 index 000000000000..0f515fc81571 --- /dev/null +++ b/gradle/publications.gradle @@ -0,0 +1,40 @@ +apply plugin: "maven-publish" + +publishing { + publications { + springFramework(MavenPublication) { + pom { + name = project.description + description = project.description + url = "https://github.com/spring-projects/spring-framework" + organization { + name = "Spring IO" + url = "https://spring.io/projects/spring-framework" + } + licenses { + license { + name = "Apache License, Version 2.0" + url = "https://www.apache.org/licenses/LICENSE-2.0" + distribution = "repo" + } + } + scm { + url = "https://github.com/spring-projects/spring-framework" + connection = "scm:git:git://github.com/spring-projects/spring-framework" + developerConnection = "scm:git:git://github.com/spring-projects/spring-framework" + } + developers { + developer { + id = "jhoeller" + name = "Juergen Hoeller" + email = "jhoeller@pivotal.io" + } + } + issueManagement { + system = "GitHub" + url = "https://github.com/spring-projects/spring-framework/issues" + } + } + } + } +} \ No newline at end of file diff --git a/gradle/spring-module.gradle b/gradle/spring-module.gradle index c817ea519006..a0e424fe3ee7 100644 --- a/gradle/spring-module.gradle +++ b/gradle/spring-module.gradle @@ -1,7 +1,7 @@ apply plugin: 'org.springframework.build.compile' apply plugin: 'org.springframework.build.optional-dependencies' apply plugin: 'org.springframework.build.test-sources' -apply plugin: "maven" +apply from: "$rootDir/gradle/publications.gradle" jar { manifest.attributes["Implementation-Title"] = project.name @@ -47,66 +47,14 @@ task javadocJar(type: Jar) { from javadoc } -artifacts { - archives sourcesJar - archives javadocJar -} - -install { - repositories.mavenInstaller { - customizePom(pom, project) +publishing { + publications { + springFramework(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + } } } -def customizePom(pom, gradleProject) { - pom.whenConfigured { generatedPom -> - // eliminate test-scoped dependencies (no need in maven central poms) - generatedPom.dependencies.removeAll { dep -> - dep.scope == "test" - } - - // sort to make pom dependencies order consistent to ease comparison of older poms - generatedPom.dependencies = generatedPom.dependencies.sort { dep -> - "$dep.scope:$dep.groupId:$dep.artifactId" - } - def managedVersions = dependencyManagement.managedVersions - generatedPom.dependencies.findAll{dep -> !dep.version }.each { dep -> - dep.version = managedVersions["${dep.groupId}:${dep.artifactId}"] - } - - // add all items necessary for maven central publication - generatedPom.project { - name = gradleProject.description - description = gradleProject.description - url = "https://github.com/spring-projects/spring-framework" - organization { - name = "Spring IO" - url = "https://projects.spring.io/spring-framework" - } - licenses { - license { - name "Apache License, Version 2.0" - url "https://www.apache.org/licenses/LICENSE-2.0" - distribution "repo" - } - } - scm { - url = "https://github.com/spring-projects/spring-framework" - connection = "scm:git:git://github.com/spring-projects/spring-framework" - developerConnection = "scm:git:git://github.com/spring-projects/spring-framework" - } - developers { - developer { - id = "jhoeller" - name = "Juergen Hoeller" - email = "jhoeller@pivotal.io" - } - } - issueManagement { - system = "GitHub" - url = "https://github.com/spring-projects/spring-framework/issues" - } - } - } -} diff --git a/integration-tests/integration-tests.gradle b/integration-tests/integration-tests.gradle index 4fef2249f6c7..1043c60a09cd 100644 --- a/integration-tests/integration-tests.gradle +++ b/integration-tests/integration-tests.gradle @@ -19,4 +19,9 @@ dependencies { testCompile("org.aspectj:aspectjweaver:${aspectjVersion}") testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") testCompile("org.hibernate:hibernate-core:5.1.17.Final") -} \ No newline at end of file +} + +// Avoid publishing JAR to the artifact repository +if (pluginManager.hasPlugin("com.jfrog.artifactory")) { + artifactoryPublish.skip = true +} diff --git a/spring-core/kotlin-coroutines/kotlin-coroutines.gradle b/spring-core/kotlin-coroutines/kotlin-coroutines.gradle index 16b11d554fd9..0eadb3e08dc9 100644 --- a/spring-core/kotlin-coroutines/kotlin-coroutines.gradle +++ b/spring-core/kotlin-coroutines/kotlin-coroutines.gradle @@ -10,8 +10,8 @@ dependencies { compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") } -// Avoid publishing coroutines JAR to the artifact repository -if (pluginManager.hasPlugin("artifactoryPublish")) { +// Avoid publishing JAR to the artifact repository +if (pluginManager.hasPlugin("com.jfrog.artifactory")) { artifactoryPublish.skip = true }