Why does sbt build fail with "MissingRequirementError: object scala.runtime in compiler mirror not found."?

The issue is when you clear all the project dependencies up while setting yours, i.e. using := not ++= or += to add dependencies to libraryDependencies in a build definition, say in build.sbt:

libraryDependencies := Dependencies.microservice

With := all the current dependencies that sbt sets upfront in libraryDependencies are cleared out and the only available dependencies are these from Dependencies.microservice (as in the above example).

Adding up "org.scala-lang" % "scala-library" % "2.10.1" (or whatever version of scalaVersion you use) is just a workaround for clearing out the already-properly-initialized libraryDependencies setting.

It's easily to reproduce with the following build definition - build.sbt:

libraryDependencies := Seq()

Trying to compile Scala files results in the error - note show libraryDependencies:

➜  clear-library-dependencies  xsbt
JAVA_HOME=/Library/Java/JavaVirtualMachines/java8/Contents/Home
SBT_OPTS= -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF-8
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Updating {file:/Users/jacek/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to clear-library-dependencies (in build file:/Users/jacek/dev/sandbox/clear-library-dependencies/)
[clear-library-dependencies]> show libraryDependencies
[info] List()
[clear-library-dependencies]> compile
[info] Updating {file:/Users/jacek/dev/sandbox/clear-library-dependencies/}clear-library-dependencies...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jacek/dev/sandbox/clear-library-dependencies/target/scala-2.10/classes...
[trace] Stack trace suppressed: run last compile:compileIncremental for the full output.
[error] (compile:compileIncremental) scala.reflect.internal.MissingRequirementError: object scala.runtime in compiler mirror not found.
[error] Total time: 0 s, completed Feb 3, 2015 10:36:08 PM

Change the build to the following (not usable, but just to show the point):

libraryDependencies ++= Seq()

The result's going to be as follows:

[clear-library-dependencies]> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to clear-library-dependencies (in build file:/Users/jacek/dev/sandbox/clear-library-dependencies/)
[clear-library-dependencies]> show libraryDependencies
[info] List(org.scala-lang:scala-library:2.10.4)
[clear-library-dependencies]> compile
[info] Updating {file:/Users/jacek/dev/sandbox/clear-library-dependencies/}clear-library-dependencies...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/jacek/dev/sandbox/clear-library-dependencies/target/scala-2.10/classes...
[success] Total time: 1 s, completed Feb 3, 2015 10:38:19 PM

Adding scala-library as a project dependency:

"org.scala-lang" % "scala-library" % "2.10.1"

Did the trick. Still not sure why this is necessary now but wasn't before.


The thing that ended up alleviating this error for me was downgrading my java version. I recently upgraded to Java 10 which seems to have compatibility issues with some versions of scala (at the very least it has problems with scala 2.12), so moving down to Java 8 did the trick.