[2.x] fix: Restore Scala 2 artifact version unification (#8689) (#8700)

Commit 92b0564dc (fix for #8632) changed `csrSameVersions` so that Scala 2.13+ only aligned `scala-library` and `scala3-library`. This removed `scala-compiler` and `scala-reflect` from version
unification, so transitive dependencies pulling in an older `scala-compiler` (e.g. 2.13.15 via `refined_2.13`) were no longer evicted to match `scalaVersion` (e.g. 2.13.18).
This commit is contained in:
calm 2026-02-06 18:55:41 -06:00 committed by GitHub
parent 4e0180d759
commit 772f616a29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -3151,16 +3151,24 @@ object Classpaths {
}).value),
csrSameVersions ++= {
partialVersion(scalaVersion.value) match {
case Some((major, minor)) if major == 2 && minor < 13 =>
// See https://github.com/sbt/sbt/issues/8689
// Scala 2.x should align all Scala 2 artifacts (scala-library, scala-compiler, scala-reflect, etc.)
case Some((major, _)) if major == 2 =>
ScalaArtifacts.Artifacts
.map(a => InclExclRule(scalaOrganization.value, a))
.toSet :: Nil
// Due to the Scala 2.13-3.x sandwich, the absence of scala-reflect
// that corresponds with scala-library 3.8.x propagates to 2.13 builds as well.
case _ =>
// Scala 3.0-3.7 uses the Scala 2.13 standard library, so align all Scala 2 artifacts
case Some((3, minor)) if minor < 8 =>
ScalaArtifacts.Artifacts
.map(a => InclExclRule(scalaOrganization.value, a))
.toSet :: Nil
// Scala 3.8+ has its own scala-library, only align library artifacts
// See https://github.com/sbt/sbt/issues/8224
case Some((3, _)) =>
ScalaArtifacts.Scala3_8Artifacts
.map(a => InclExclRule(scalaOrganization.value, a))
.toSet :: Nil
case _ => Nil
}
},
moduleName := normalizedName.value,

View File

@ -1 +1,3 @@
> update
# Scala 3.8+ no longer supports being included into Scala 2.13 classpath
> a/update
-> b/update

View File

@ -3,12 +3,12 @@ import sbt.librarymanagement.InclExclRule
lazy val a = project.settings(
scalaVersion := "2.13.11",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
TaskKey[Unit]("checkLibs") := checkLibs("2.13.11", (Compile/dependencyClasspath).value, ".*scala-library.*"),
TaskKey[Unit]("checkLibs") := checkLibs("2.13.11", (Compile/dependencyClasspath).value, ".*scala-(library|reflect).*"),
)
lazy val b = project.dependsOn(a).settings(
scalaVersion := "2.13.12",
TaskKey[Unit]("checkLibs") := checkLibs("2.13.12", (Compile/dependencyClasspath).value, ".*scala-library.*"),
TaskKey[Unit]("checkLibs") := checkLibs("2.13.12", (Compile/dependencyClasspath).value, ".*scala-(library|reflect).*"),
)
lazy val a3 = project.settings(

View File

@ -15,5 +15,6 @@ $ delete s2.13.14.txt
# without the default `csrSameVersions`, scala-reflect in b stays at 2.13.11
> set b/csrSameVersions := Nil
> b/update
-> b/checkLibs
> ak/checkLibs