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 -> configure(javaProjects) { javaProject ->
test { 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) { configure(rootProject) {
description = "Spring Web Flow" description = "Spring Web Flow"

View File

@@ -1,27 +1,26 @@
apply plugin: "maven" apply plugin: "maven-publish"
install { publishing {
repositories.mavenInstaller { publications {
customizePom(pom, project) 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 {
def customizePom(pom, gradleProject) { afterEvaluate {
pom.whenConfigured { generatedPom -> description = project.description
// eliminate test-scoped dependencies (no need in maven central poms) name = project.description
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" url = "https://github.com/spring-projects/spring-webflow"
organization { organization {
name = "Spring IO" name = "Spring IO"
@@ -29,9 +28,9 @@ def customizePom(pom, gradleProject) {
} }
licenses { licenses {
license { license {
name "The Apache Software License, Version 2.0" name = "The Apache Software License, Version 2.0"
url "https://www.apache.org/licenses/LICENSE-2.0.txt" url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo" distribution = "repo"
} }
} }
scm { scm {
@@ -53,3 +52,10 @@ def customizePom(pom, gradleProject) {
} }
} }
} }
}
// Disable generation of Gradle Module Metadata for compatibility
// with older versions of Spring Web Flow.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}