8000 Let ++ fall back to a bincompat Scala version · sbt/sbt@de20328 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit de20328

Browse files
committed
Let ++ fall back to a bincompat Scala version
Fixes #7327 **Problem** In builds with mixed Scala patch versions (like scalameta), it's possible for a core subproject to be set to the lastest 2.12.x, but the compiler plugin component is cross published to 2.12.0 etc. `++ 2.12.0` in this case does not work since sbt 1.7.x onwards requires the queried Scala version to be listed in `crossScalaVersions`. **Solution** This implements sbt 1.6.x-like fallback mechanism, but instead of using the queried version (e.g. 2.12.0) it will set the Scala version to one of listed versions that is binary compatible.
1 parent 4b0b929 commit de20328

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

main/src/main/scala/sbt/Cross.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import sbt.internal.util.MessageOnlyException
2020
import sbt.internal.util.complete.DefaultParsers._
2121
import sbt.internal.util.complete.{ DefaultParsers, Parser }
2222
import sbt.io.IO
23-
import sbt.librarymanagement.{ SemanticSelector, VersionNumber }
23+
import sbt.librarymanagement.{ CrossVersion, SemanticSelector, VersionNumber }
2424

2525
/**
2626
* Cross implements the Scala cross building commands:
@@ -340,8 +340,23 @@ object Cross {
340340
case (project, scalaVersions) =>
341341
val selector = SemanticSelector(version)
342342
scalaVersions.filter(v => selector.matches(VersionNumber(v))) match {
343-
case Nil => (project, None, scalaVersions)
344343
case Seq(version) => (project, Some(version), scalaVersions)
344+
case Nil =>
345+
// The Scala version queried via ++, like ++2.13.1 was not found.
346+
// However, it's possible to keep the build going by falling back to a
347+
// binary-compatible Scala version if available.
348+
// In sbt 1.6.x (prior to https://github.com/sbt/sbt/pull/6946), we use to
349+
// use the queried ++2.13.1 version as the fallback, which was wrong and unsafe.
350+
// Instead this picks an actual Scala version listed in `crossScalaVersion`.
351+
val svOpt = scalaVersions.find(
352+
CrossVersion.isScalaBinaryCompatibleWith(newVersion = version, _)
353+
)
354+
svOpt.foreach { sv =>
355+
state.log.info(
356+
s"Falling back ${project.project} to listed $sv instead of unlisted $version"
357+
)
358+
}
359+
(project, svOpt, scalaVersions)
345360
case multiple =>
346361
sys.error(
347362
s"Multiple crossScalaVersions matched query '$version': ${multiple.mkString(", ")}"

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.9.0
1+
sbt.version=1.9.1

sbt-app/src/sbt-test/actions/cross-strict-aggregation/test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
-> ++2.12.0-magic
22

3-
-> ++2.12.12
3+
> ++2.12.12
4+
5+
> clean
46

57
> ++2.13.11 compile
68

0 commit comments

Comments
 (0)
0