Skip to content

Commit

Permalink
Optional scala suffix in artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mgosk committed Oct 23, 2024
1 parent 1d558c1 commit 493c9b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================

Expand Down
6 changes: 5 additions & 1 deletion src/main/groovy/com/adtran/ScalaMultiVersionPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ class ScalaMultiVersionPlugin implements Plugin<Project> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 493c9b5

Please sign in to comment.