After more testing and thinking, I found some issues related to the fact that scala-reflect
and scala-compiler
are built using -opt-inline-from:scala/**
(inlining from scala-library).
-
The
console
task runs thescalaVersion
of the REPL. On the runtime classpath, the scala-library version needs to match the REPL (code was inlined into the REPL). On REPL’s compile-time classpath we might want the updated scala-library for consistency with thecompile
task. But this is broken: using new definitions in the updated library only works when compiling the RPEL line, but then fails to run. -
Using scala-relfect (
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
). If another dependency forces an update of scala-library, the bytecode in scala-reflect may crash at runtime (NoSuchMethodError). -
The same issue would show up in projects that use scala-compiler in some way (and probably also scalap), for example when using Scala as a JSR 223 scripting engine.
This needs to be addressed. Maybe your idea to fail the build could come into play here. If the classpath contains scala-reflect or scala-compiler and the version doesn’t match scala-library, the user needs to adjust the scalaVersion
.
For the REPL, we could emit a warning and use a scalaInstance
based on the updated scala-library version.