title: Test in Eclipse works but sbt throws MissingRequirementError: object scala.runtime in compiler mirror not found
body: <p>I am messing around with parsing and <code>scala.tools.nsc.interactive.Global</code> in Scala and I ran into a problem while executing tests under sbt. The tests run fine from Eclipse both with <code>JUnitRunner</code> and the <code>ScalaTest</code> plugin. After long time spent on Google I can't figure out how to fix this.</p>
  
  <p>When I execute <code>sbt test</code> the following error is thrown: </p>
  
  <pre><code>Exception encountered when attempting to run a suite with class name: compileutils.CompileTest *** ABORTED ***
  [info]   java.lang.ExceptionInInitializerError:
  [info]   at compileutils.CompileTest$$anonfun$3.apply$mcV$sp(CompileTest.scala:18)
  [info]   at compileutils.CompileTest$$anonfun$3.apply(CompileTest.scala:16)
  [info]   at compileutils.CompileTest$$anonfun$3.apply(CompileTest.scala:16)
  [info]   at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
  [info]   at org.scalatest.Transformer$$anonfun$apply$1.apply(Transformer.scala:22)
  [info]   at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
  [info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
  [info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
  [info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
  [info]   at org.scalatest.FunSuiteLike$$anon$1.apply(FunSuiteLike.scala:158)
  [info]   ...
  [info]   Cause: scala.reflect.internal.MissingRequirementError: object scala.runtime in compiler mirror not found.
  [info]   at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
  [info]   at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
  [info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
  [info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
  [info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
  [info]   at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:172)
  [info]   at scala.reflect.internal.Mirrors$RootsBase.getRequiredPackage(Mirrors.scala:175)
  [info]   at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage$lzycompute(Definitions.scala:183)
  [info]   at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage(Definitions.scala:183)
  [info]   at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackageClass$lzycompute(Definitions.scala:184)
  [info]   ...
  </code></pre>
  
  <p><strong>The class under test</strong> </p>
  
  <pre><code>package compileutils
  
  import scala.tools.nsc.Settings
  import scala.tools.nsc.interactive.Global
  import scala.tools.nsc.reporters.ConsoleReporter
  import scala.tools.nsc.interactive.Response
  import scala.io.Source
  import scala.reflect.internal.util.SourceFile
  import scala.reflect.internal.util.BatchSourceFile
  import scala.reflect.io.AbstractFile
  import java.io.File
  
  object Compile {
    val settings = new Settings
    val reporter = new ConsoleReporter(settings)
    val global = new Global(settings, reporter, "Study compile")
  
    def parse(source: String): Compile.this.global.Tree = {
      val sourceFile = new BatchSourceFile(".", source)
      global.askReload(List(sourceFile), new Response[Unit])
  
      global.parseTree(sourceFile)
    }
  
    def loadTypes(source: String): Either[Compile.this.global.Tree, Throwable] = {
      val sourceFile = new BatchSourceFile(".", source)
      val tResponse = new Response[global.Tree]
      global.askReload(List(sourceFile), new Response[Unit])
      global.askLoadedTyped(sourceFile, tResponse)
  
      tResponse.get
    }
  
  }
  </code></pre>
  
  <p><strong>The test</strong></p>
  
  <pre><code>package compileutils
  
  import org.scalatest.BeforeAndAfter
  import org.junit.runner.RunWith
  import org.scalatest.junit.JUnitRunner
  import org.scalatest.FunSuite
  import org.scalatest.Matchers._
  
  @RunWith(classOf[JUnitRunner])
  class CompileTest extends FunSuite with BeforeAndAfter {
    val testSource = "class FromString {val s = \"dsasdsad \"}"
  
    before {}
    after {}
  
    test("parse") {
      //when
      val tree = Compile.parse(testSource)
  
      //then
      tree should not be null
    }
  
    test("typer") {
      //when
      val typ = Compile.loadTypes(testSource)
  
      //then
      typ should be('left)
    }
  }
  </code></pre>
  
  <p><strong>build.sbt</strong></p>
  
  <pre><code>name := "Compiler study"
  
  version := "0.1"
  
  val scalaBuildVersion = "2.10.3"
  
  scalaVersion := scalaBuildVersion
  
  libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaBuildVersion
  
  libraryDependencies += "org.scala-lang" % "scala-library" % scalaBuildVersion
  
  libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaBuildVersion
  
  libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.0" % "test"
  
  libraryDependencies += "junit" % "junit" % "4.11" % "test"
  </code></pre>
  
  <p>Environment:</p>
  
  <pre><code>sbt launcher version 0.13.0
  Scala compiler version 2.10.3 -- Copyright 2002-2013, LAMP/EPFL
  javac 1.6.0_45
  DISTRIB_ID=Ubuntu
  DISTRIB_RELEASE=13.10
  DISTRIB_CODENAME=saucy
  DISTRIB_DESCRIPTION="Ubuntu 13.10"
  </code></pre>