[2.x] fix: Include platform suffix in Artifact.artifactName (#9118)

This commit is contained in:
Anatolii Kmetiuk 2026-04-22 11:58:34 +09:00 committed by Anatolii Kmetiuk
parent ef36bdaa15
commit afac251f28
6 changed files with 85 additions and 1 deletions

View File

@ -104,7 +104,15 @@ private[librarymanagement] abstract class ArtifactFunctions {
import artifact.*
val classifierStr = classifier match { case None => ""; case Some(c) => "-" + c }
val cross = CrossVersion(module.crossVersion, scalaVersion.full, scalaVersion.binary)
val base = CrossVersion.applyCross(artifact.name, cross)
val withPlatform = module.crossVersion match {
case _: Disabled => artifact.name
case _ =>
module.platformOpt match {
case Some(p) if p.nonEmpty && p != Platform.jvm => s"${artifact.name}_$p"
case _ => artifact.name
}
}
val base = CrossVersion.applyCross(withPlatform, cross)
base + "-" + module.revision + classifierStr + "." + artifact.extension
}

View File

@ -0,0 +1,41 @@
package sbt.librarymanagement
import sbt.internal.librarymanagement.UnitSpec
class ArtifactTest extends UnitSpec {
"Artifact.artifactName" should "include the platform suffix before the Scala suffix" in {
val m = ModuleID("com.example", "root-178", "0.1.0-SNAPSHOT")
.cross(CrossVersion.binary)
.platform("native0.5")
val a = Artifact("root-178", "pom", "pom")
val sv = ScalaVersion("3.8.3", "3")
Artifact.artifactName(sv, m, a) shouldBe "root-178_native0.5_3-0.1.0-SNAPSHOT.pom"
}
it should "omit the platform suffix for jvm" in {
val m = ModuleID("com.example", "foo", "1.0.0")
.cross(CrossVersion.binary)
.platform(Platform.jvm)
val a = Artifact("foo", "jar", "jar")
Artifact.artifactName(ScalaVersion("3.8.3", "3"), m, a) shouldBe "foo_3-1.0.0.jar"
}
it should "omit platform and cross suffix when crossVersion is disabled" in {
val m = ModuleID("com.example", "foo", "1.0.0").platform("native0.5")
val a = Artifact("foo", "jar", "jar")
Artifact.artifactName(ScalaVersion("3.8.3", "3"), m, a) shouldBe "foo-1.0.0.jar"
}
it should "produce a filename whose base matches the Maven coordinate (#9117)" in {
val m = ModuleID("com.indoorvivants", "sniper", "0.0.9-SNAPSHOT")
.cross(CrossVersion.binary)
.platform("native0.5")
val a = Artifact("sniper", "pom", "pom")
val sv = ScalaVersion("3.8.3", "3")
val expectedMavenArtifactId = "sniper_native0.5_3"
Artifact.artifactName(sv, m, a) shouldBe
s"$expectedMavenArtifactId-0.0.9-SNAPSHOT.pom"
}
}

View File

@ -107,4 +107,21 @@ final class FromSbtPlatformSpec extends AnyPropSpec with Matchers {
// Should just have cross-version suffix, no platform
module.name.value shouldBe "qux_2.13"
}
property("issue #9117: project with native0.5 publishes as _native0.5_3") {
val projectID = ModuleID("com.indoorvivants", "sniper", "0.0.9-SNAPSHOT")
.withCrossVersion(Binary())
.platform("native0.5")
val (module, version) = FromSbt.moduleVersion(
projectID,
scalaVersion = "3.8.3",
scalaBinaryVersion = "3",
optionalCrossVer = false,
projectPlatform = Some("native0.5")
)
module.name.value shouldBe "sniper_native0.5_3"
version shouldBe "0.0.9-SNAPSHOT"
}
}

View File

@ -3589,6 +3589,7 @@ object Classpaths {
val p0 = ModuleID(organization.value, moduleName.value, version.value)
.cross((projectID / crossVersion).value)
.artifacts(artifacts.value*)
.withPlatformOpt(platform.?.value)
val p1 = apiURL.value match
case Some(u) => p0.extra(SbtPomExtraProperties.POM_API_KEY -> u.toURL().toExternalForm)
case _ => p0

View File

@ -0,0 +1,16 @@
ThisBuild / organization := "com.example"
name := "testproj"
version := "0.1.0-SNAPSHOT"
scalaVersion := "3.8.3"
platform := "native0.5"
crossVersion := CrossVersion.binary
lazy val checkPomName = taskKey[Unit]("check POM artifact path includes native0.5_3")
checkPomName := {
val converter = fileConverter.value
val p = (makePom / artifactPath).value
val s = converter.toPath(p).toString
assert(s.contains("native0.5_3"), s"expected native0.5_3 in POM path, got: $s")
}

View File

@ -0,0 +1 @@
> checkPomName