sbt

sbt compileで scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found


今回は最近ハマったしょうもないバグについて。

普通にScalaコードを書いていて、いざビルドするぞとsbt compileを叩いたところ以下のようなエラーが出ました。

 

[error] error while loading Object, Missing dependency 'object scala in compiler mirror', required by /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
 at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
 at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
 at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:53)
 at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
 at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:173)
 at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:161)
 at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:161)
 at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:162)
 at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:162)
 at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1391)
 at scala.tools.nsc.Global$Run.<init>(Global.scala:1242)
 at xsbt.CachedCompiler0$$anon$2.<init>(CompilerInterface.scala:106)
 at xsbt.CachedCompiler0.run(CompilerInterface.scala:106)
 at xsbt.CachedCompiler0.run(CompilerInterface.scala:95)
 at xsbt.CompilerInterface.run(CompilerInterface.scala:26)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:107)
 at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:53)
 at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
 at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:50)
 at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
 at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
 at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:74)
 at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:49)
 at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:64)
 at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
 at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
 at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
 at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
 at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:32)
 at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:72)
 at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:71)
 at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:99)
 at sbt.inc.Incremental$.compile(Incremental.scala:71)
 at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
 at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160)
 at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138)
 at sbt.Compiler$.compile(Compiler.scala:155)
 at sbt.Compiler$.compile(Compiler.scala:141)
 at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:886)
 at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:877)
 at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:875)
 at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
 at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
 at sbt.std.Transform$$anon$4.work(System.scala:63)
 at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
 at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
 at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
 at sbt.Execute.work(Execute.scala:237)
 at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
 at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
 at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
 at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
[error] (compile:compileIncremental) scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.

 

object scalaが無いって言ってます。

結論はこっちのStackOverflowで言ってることとほぼ同じなのですが。英語力がなくて、すぐに気付けなかった・・・。

https://stackoverflow.com/questions/16329566/why-does-sbt-build-fail-with-missingrequirementerror-object-scala-runtime-in-c

object scalaが無いのはscala-library.jarがちゃんと依存に入ってないから出ます。その理由は以下のlibraryDependenciesでした。

lazy val root = project.in(file("."))
  .settings(
    name := "gcp-example",
    organization := "tsukaby",
    version := "1.0.0",
    scalaVersion := "2.11.11",
    libraryDependencies := Seq(
      "com.google.cloud" % "google-cloud-pubsub" % "0.20.1-beta",
      "joda-time" % "joda-time" % "2.9.2"
    )
  )

こんな感じで書いてたんですが、

libraryDependencies := Seq(

これですね・・・。正しくはこうです。

libraryDependencies ++= Seq(

:= と書いてたので、デフォルトであるscala-libraryの依存が消えちゃってたのかな。

というわけで下らないオチでした。みなさんお気をつけて。