Adopt new Gradle maven-publish plugin

The maven plugin was removed in Gradle 7, so we need to replace it with
maven-publish. This uses a similar DSL, but operates in a slightly
different way. The simplest way of handling the differences is to
reorder its application within build.gradle so that appropriate
properties will have been applied by the time publish-maven.gradle
is invoked.
This commit is contained in:
Ian Young
2022-05-05 09:59:56 +01:00
committed by rstoyanchev
parent 014c3d4893
commit 2e3750dbc0
2 changed files with 81 additions and 75 deletions

View File

@@ -99,30 +99,6 @@ allprojects {
}
subprojects { subproject ->
apply from: "${rootProject.projectDir}/publish-maven.gradle"
sourceCompatibility=1.8
targetCompatibility=1.8
[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none"]
sourceSets.test.resources.srcDirs = ["src/main/java", "src/test/resources", "src/test/java"]
jar {
manifest.attributes["Implementation-Title"] = subproject.name
manifest.attributes["Implementation-Version"] = subproject.version
from("${rootProject.projectDir}/src/dist") {
include "license.txt"
include "notice.txt"
into "META-INF"
expand(copyright: new Date().format("yyyy"), version: project.version)
}
}
}
configure(javaProjects) { javaProject ->
test {
@@ -154,6 +130,30 @@ configure(javaProjects) { javaProject ->
}
}
subprojects { subproject ->
apply from: "${rootProject.projectDir}/publish-maven.gradle"
sourceCompatibility=1.8
targetCompatibility=1.8
[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none"]
sourceSets.test.resources.srcDirs = ["src/main/java", "src/test/resources", "src/test/java"]
jar {
manifest.attributes["Implementation-Title"] = subproject.name
manifest.attributes["Implementation-Version"] = subproject.version
from("${rootProject.projectDir}/src/dist") {
include "license.txt"
include "notice.txt"
into "META-INF"
expand(copyright: new Date().format("yyyy"), version: project.version)
}
}
}
configure(rootProject) {
description = "Spring Web Flow"

View File

@@ -1,55 +1,61 @@
apply plugin: "maven"
apply plugin: "maven-publish"
install {
repositories.mavenInstaller {
customizePom(pom, project)
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
if (project.name != 'spring-js-resources') {
artifact sourcesJar
artifact javadocJar
}
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
afterEvaluate {
description = project.description
name = project.description
}
url = "https://github.com/spring-projects/spring-webflow"
organization {
name = "Spring IO"
url = "https://spring.io/projects/spring-webflow"
}
licenses {
license {
name = "The Apache Software License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "repo"
}
}
scm {
url = "https://github.com/spring-projects/spring-webflow"
connection = "scm:git:git://github.com/spring-projects/spring-webflow"
developerConnection = "scm:git:git://github.com/spring-projects/spring-webflow"
}
developers {
developer {
id = "rstoyanchev"
name = "Rossen Stoyanchev"
email = "rstoyanchev@pivotal.io"
}
}
issueManagement {
system = "Jira"
url = "https://jira.spring.io/browse/SWF"
}
}
}
}
}
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"
}
// add all items necessary for maven central publication
generatedPom.project {
name = gradleProject.description
description = gradleProject.description
url = "https://github.com/spring-projects/spring-webflow"
organization {
name = "Spring IO"
url = "https://spring.io/projects/spring-webflow"
}
licenses {
license {
name "The Apache Software License, Version 2.0"
url "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
scm {
url = "https://github.com/spring-projects/spring-webflow"
connection = "scm:git:git://github.com/spring-projects/spring-webflow"
developerConnection = "scm:git:git://github.com/spring-projects/spring-webflow"
}
developers {
developer {
id = "rstoyanchev"
name = "Rossen Stoyanchev"
email = "rstoyanchev@pivotal.io"
}
}
issueManagement {
system = "Jira"
url = "https://jira.spring.io/browse/SWF"
}
}
}
// Disable generation of Gradle Module Metadata for compatibility
// with older versions of Spring Web Flow.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}