From 2e3750dbc016e91c7311cfecdbb253fe2a422752 Mon Sep 17 00:00:00 2001 From: Ian Young Date: Thu, 5 May 2022 09:59:56 +0100 Subject: [PATCH] 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. --- build.gradle | 48 +++++++++---------- publish-maven.gradle | 108 +++++++++++++++++++++++-------------------- 2 files changed, 81 insertions(+), 75 deletions(-) diff --git a/build.gradle b/build.gradle index 67350aec..44d5845c 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/publish-maven.gradle b/publish-maven.gradle index afe09a21..889ee721 100644 --- a/publish-maven.gradle +++ b/publish-maven.gradle @@ -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 }