将Scala演示文稿编译器与sbt一起使用时出现问题

时间:2018-11-02 11:07:43

标签: scala sbt

我正在尝试使用Scala演示文稿编译器,但即使运行一个最小的示例也遇到了问题:

import scala.tools.nsc.Settings
import scala.tools.nsc.interactive.Global
import scala.tools.nsc.reporters.ConsoleReporter

object Sandbox extends App {

   val settings = new Settings()
   val reporter = new ConsoleReporter(settings)
   val compiler = new Global(settings, reporter)

}

我的build.sbt看起来像这样:

name := "blah"

version := "0.1"

scalaVersion := "2.12.7"

libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.12.7"

我正在使用sbt 1.2.6(也尝试过其他版本)。它编译正常,但是当我运行时我得到了:

sbt:blah> compile
[success] Total time: 0 s, completed Nov 2, 2018 11:52:01 AM
sbt:blah> run
[info] Running Sandbox
error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
[error] (run-main-0) scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
[error] scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
[error]     at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
[error]     at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
[error]     at scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$4(Mirrors.scala:54)
[error]     at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:54)
[error]     at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
[error]     at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:172)
[error]     at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:189)
[error]     at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:189)
[error]     at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:190)
[error]     at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:190)
[error]     at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1455)
[error]     at scala.tools.nsc.Global$Run.<init>(Global.scala:1179)
[error]     at scala.tools.nsc.interactive.Global$TyperRun.<init>(Global.scala:1314)
[error]     at scala.tools.nsc.interactive.Global.newTyperRun(Global.scala:1337)
[error]     at scala.tools.nsc.interactive.Global.<init>(Global.scala:286)
[error]     at Sandbox$.delayedEndpoint$Sandbox$1(Sandbox.scala:9)
[error]     at Sandbox$delayedInit$body.apply(Sandbox.scala:5)
[error]     at scala.Function0.apply$mcV$sp(Function0.scala:34)
[error]     at scala.Function0.apply$mcV$sp$(Function0.scala:34)
[error]     at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[error]     at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error]     at scala.collection.immutable.List.foreach(List.scala:388)
[error]     at scala.App.main(App.scala:76)
[error]     at scala.App.main$(App.scala:74)
[error]     at Sandbox$.main(Sandbox.scala:5)
[error]     at Sandbox.main(Sandbox.scala)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]     at java.lang.reflect.Method.invoke(Method.java:498)
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1
[error] Total time: 1 s, completed Nov 2, 2018 11:52:04 AM

如您所见,我将Scala 2.12.7与Java jdk1.8.0_181结合使用。

0 个答案:

没有答案