Skip to content

Commit

Permalink
Override Scala version for sbt 1.4.x
Browse files Browse the repository at this point in the history
Problem
-------
During sbt 1.4.x series util-interface incorrectly depended on
scala-library. Specifically for util-interface 1.4.0, 1.4.1, and 1.4.2,
this was Scala 2.13. Ivy seemed to be ok with this, but Coursier evicts
Scala 2.12 and resolves to 2.13, which creating a confusing
`java.lang.NoClassDefFoundError: scala/Serializable` error.

Solution
--------
Explicitly override Scala version for sbt 1.4.x to Scala 2.12.12.
  • Loading branch information
eed3si9n committed Jul 11, 2021
1 parent 3ed167d commit 3e19f1c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 0 additions & 2 deletions ci-test/app2/sbt.1.4.0.boot.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

[repositories]
local
local-preloaded-ivy: file:///${sbt.preloaded-${sbt.global.base-${user.home}/.sbt}/preloaded/}, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
local-preloaded: file:///${sbt.preloaded-${sbt.global.base-${user.home}/.sbt}/preloaded/}
maven-central
sbt-maven-releases: https://repo.scala-sbt.org/scalasbt/maven-releases/, bootOnly
sbt-maven-snapshots: https://repo.scala-sbt.org/scalasbt/maven-snapshots/, bootOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import coursier.core.{ Publication, Repository }
import coursier.credentials.DirectCredentials
import coursier.ivy.IvyRepository
import coursier.maven.MavenRepository
import coursier.params.ResolutionParams
import java.io.{ File, FileWriter, PrintWriter }
import java.nio.file.{ Files, StandardCopyOption, Paths }
import java.util.Properties
Expand Down Expand Up @@ -108,10 +109,19 @@ class CousierUpdate(config: UpdateConfiguration) {
deps: List[Dependency]
): UpdateResult = {
val repos = config.repositories.map(toCoursierRepository)
val params = scalaVersion match {
case Some(sv) if sv != "auto" =>
ResolutionParams()
.withScalaVersion(sv)
.withForceScalaVersion(true)
case _ =>
ResolutionParams()
}
val r: Resolution = Resolve()
.withCache(coursierCache)
.addDependencies(deps: _*)
.withRepositories(repos)
.withResolutionParams(params)
.run()
val actualScalaVersion =
(r.dependencySet.set collect {
Expand Down Expand Up @@ -143,6 +153,7 @@ class CousierUpdate(config: UpdateConfiguration) {
.withCache(coursierCache)
.addDependencies(deps: _*)
.withRepositories(repos)
.withResolutionParams(params)
.run()
downloadedJars foreach { downloaded =>
val t =
Expand Down
13 changes: 12 additions & 1 deletion launcher-implementation/src/main/scala/xsbt/boot/Launch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,20 @@ class Launch private[xsbt] (

@tailrec private[this] final def getAppProvider0(
id: xsbti.ApplicationID,
explicitScalaVersion: Option[String],
explicitScalaVersion0: Option[String],
forceAppUpdate: Boolean
): xsbti.AppProvider = {
val explicitScalaVersion = explicitScalaVersion0 match {
case Some(sv) => Some(sv)
case _ =>
// https://github.com/sbt/sbt/issues/6587
// set the Scala version of sbt 1.4.x series to 2.12.12 explicitly
// since util-interface depends on Scala 2.13 by mistake
// https://github.com/sbt/sbt/blob/v1.4.0/project/Dependencies.scala
if (id.groupID() == "org.scala-sbt" &&
id.name() == "sbt" && id.version().startsWith("1.4.")) Some("2.12.12")
else None
}
val app = appModule(id, explicitScalaVersion, true, "app")

/** Replace the version of an ApplicationID with the given one, if set. */
Expand Down

0 comments on commit 3e19f1c

Please sign in to comment.