From 7b5d9e81df879a3b59862a9869e8f234d30dcdfd Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Fri, 11 Jun 2021 15:12:46 +0200 Subject: [PATCH] Introduce a BOM for Mockito's artifacts (closes #2321) --- gradle/java-library.gradle | 2 - gradle/java-publication.gradle | 72 ++++++++++++++++++++-------------- settings.gradle.kts | 3 +- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/gradle/java-library.gradle b/gradle/java-library.gradle index 7402eaeed9..bb59952481 100644 --- a/gradle/java-library.gradle +++ b/gradle/java-library.gradle @@ -1,7 +1,5 @@ apply plugin: "java" -group = 'org.mockito' - if (!archivesBaseName.startsWith("mockito-")) { archivesBaseName = "mockito-" + project.name } diff --git a/gradle/java-publication.gradle b/gradle/java-publication.gradle index b3f9abc048..8c0b255d7e 100644 --- a/gradle/java-publication.gradle +++ b/gradle/java-publication.gradle @@ -1,30 +1,35 @@ -//Sources/javadoc artifacts required by Maven module publications -def licenseSpec = copySpec { - from project.rootDir - include "LICENSE" -} +group = 'org.mockito' -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource - with licenseSpec -} +plugins.withId("java") { + //Sources/javadoc artifacts required by Maven module publications + def licenseSpec = copySpec { + from project.rootDir + include "LICENSE" + } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from tasks.javadoc - with licenseSpec -} + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + with licenseSpec + } -jar { - with licenseSpec -} + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from tasks.javadoc + with licenseSpec + } -artifacts { - archives sourcesJar - archives javadocJar + artifacts { + archives sourcesJar + archives javadocJar + } + + jar { + with licenseSpec + } } + tasks.withType(GenerateModuleMetadata) { enabled = false } @@ -34,9 +39,14 @@ apply plugin: "maven-publish" publishing { publications { javaLibrary(MavenPublication) { - from components.java - artifact sourcesJar - artifact javadocJar + plugins.withId("java") { + from components.java + artifact sourcesJar + artifact javadocJar + } + plugins.withId("java-platform") { + from components.javaPlatform + } artifactId = project.archivesBaseName @@ -44,10 +54,12 @@ publishing { name = artifactId description = project.description - //Gradle does not write 'jar' packaging to the pom (unlike other packaging types). - //This is OK because 'jar' is implicit/default: - // https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#minimal-pom - packaging = project.tasks.jar.extension + plugins.withId("java") { + //Gradle does not write 'jar' packaging to the pom (unlike other packaging types). + //This is OK because 'jar' is implicit/default: + // https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#minimal-pom + packaging = project.tasks.jar.extension + } url = "https://github.com/mockito/mockito" licenses { @@ -88,8 +100,10 @@ publishing { repositories { maven { url = "$buildDir/repo" } } } +plugins.withId("java") { //fleshes out problems with Maven pom generation when building -tasks.build.dependsOn("publishJavaLibraryPublicationToMavenLocal") + tasks.build.dependsOn("publishJavaLibraryPublicationToMavenLocal") +} apply plugin: 'signing' //https://docs.gradle.org/current/userguide/signing_plugin.html signing { diff --git a/settings.gradle.kts b/settings.gradle.kts index 530d545091..0da9ad17f2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,7 +16,8 @@ include("deprecatedPluginsTest", "memory-test", "errorprone", "junitJupiterParallelTest", - "osgi-test") + "osgi-test", + "bom") rootProject.name = "mockito"