[1.x] fix: Fixes managedScalaInstance false support (#9121) (#9123)

**Problem**
When managedScalaInstance is set to false, we stopped creating
ScalaInstance, but the documentation says the user can
pull in their own dependencies.

**Solution**
Attempt to construct a ScalaInstance from update report
even when managedScalaInstance is set to false.
This commit is contained in:
eugene yokota 2026-04-23 03:32:42 -04:00 committed by GitHub
parent 6723437f97
commit 872db3d817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 4 deletions

View File

@ -35,14 +35,18 @@ private[sbt] object Compiler {
val app = Keys.appConfiguration.value
val managed = Keys.managedScalaInstance.value
val sv = Keys.scalaVersion.value
val configs = Keys.ivyConfigurations.value
// if this logic changes, ensure that `unmanagedScalaInstanceOnly` and `update` are changed
// appropriately to avoid cycles
sh match {
case Some(h) => scalaInstanceFromHome(h)
(sh, extraToolConf) match {
case (Some(h), _) => scalaInstanceFromHome(h)
case _ if !managed =>
val extra = extraToolConf.getOrElse(Configurations.ScalaTool)
if (configs.contains(extra)) scalaInstanceFromUpdate(extraToolConf)
else emptyScalaInstance
case _ =>
val scalaProvider = app.provider.scalaProvider
if (!managed) emptyScalaInstance
else if (sv == scalaProvider.version) optimizedScalaInstance(sv, scalaProvider)
if (sv == scalaProvider.version) optimizedScalaInstance(sv, scalaProvider)
else scalaInstanceFromUpdate(extraToolConf)
}
}

View File

@ -0,0 +1,5 @@
package example
class A {
val x = 1
}

View File

@ -0,0 +1,18 @@
import Configurations.{ ScalaTool, ScalaDocTool }
@transient
lazy val check = taskKey[Unit]("")
lazy val scala213 = "2.13.16"
scalaVersion := scala213
autoScalaLibrary := false
managedScalaInstance := false
ivyConfigurations ++= List(ScalaTool, ScalaDocTool)
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % scala213,
"org.scala-lang" % "scala-compiler" % scala213 % ScalaTool,
"org.scala-lang" % "scala-compiler" % scala213 % ScalaDocTool,
)
check := {
val si = scalaInstance.value
assert(si.version == scala213, s"'${si.version}' was not '$scala213'")
}

View File

@ -0,0 +1,3 @@
> compile
> doc
> check