From 493c9b5ef05866284c5f5ebb0d4a8210a353a315 Mon Sep 17 00:00:00 2001 From: mgosk Date: Wed, 23 Oct 2024 21:40:07 +0200 Subject: [PATCH] Optional scala suffix in artifacts --- README.rst | 10 ++++++++++ .../com/adtran/ScalaMultiVersionPlugin.groovy | 6 +++++- .../TestScalaMultiVersionPluginIntegration.groovy | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 240fa30..d2dfed0 100644 --- a/README.rst +++ b/README.rst @@ -224,6 +224,16 @@ syntax. In this case, you need to use the same syntax in the substitution rule:: .. _composite builds: https://docs.gradle.org/current/userguide/composite_builds.html + +Customized publishing +================= + +By default POM files are modified by adding ``scala_version`` at end of artifactId. User might disable this behaviour by +setting ``addScalaSuffix=false`` property . + +``gradle build -PaddScalaSuffix=false`` + + Known Limitations ================= diff --git a/src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy b/src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy index c14818c..138fc5d 100644 --- a/src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy +++ b/src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy @@ -279,7 +279,11 @@ class ScalaMultiVersionPlugin implements Plugin { private void resolvePomDependencies() { project.afterEvaluate { // for projects using the maven-publish plugin - if (project.plugins.hasPlugin("maven-publish")) { + Boolean addScalaSuffix = true + if (project.ext.has("addScalaSuffix")) { + addScalaSuffix = project.ext.addScalaSuffix.toBoolean() + } + if (project.plugins.hasPlugin("maven-publish") && addScalaSuffix) { project.publishing.publications.withType(MavenPublication) { pom.withXml { resolveMavenPomDependencies(it) } artifactId += project.ext.scalaSuffix diff --git a/src/test/groovy/integration/TestScalaMultiVersionPluginIntegration.groovy b/src/test/groovy/integration/TestScalaMultiVersionPluginIntegration.groovy index f50bbf4..3643503 100644 --- a/src/test/groovy/integration/TestScalaMultiVersionPluginIntegration.groovy +++ b/src/test/groovy/integration/TestScalaMultiVersionPluginIntegration.groovy @@ -129,6 +129,20 @@ class TestScalaMultiVersionPlugin extends GroovyTestCase implements SimpleProjec assert root.artifactId.text() == "codeProject_2.12" } + void testMavenPublishPomWithoutModifications() { + def result = GradleRunner.create() + .withProjectDir(projectDir) + .withArguments("generatePomFileForMavenPublication", "-PscalaVersions=2.12.1", "-PaddScalaSuffix=false") + .build() + def pomXml = new File(projectDir, "build/publications/maven/pom-default.xml").text + assert !pomXml.contains("_%%") + assert !pomXml.contains("%scala_version%") + def root = new XmlSlurper().parseText(pomXml) + assert root.dependencies.'*'.find { it.artifactId == "scala-library" }.version.text() == '2.12.1' + assert root.dependencies.'*'.find { it.artifactId == "fake-scala-dep_2.12" } != null + assert root.artifactId.text() == "codeProject" + } + void testRunOnceTasks() { def result = GradleRunner.create() .withProjectDir(projectDir)