1

对于 Scala 2.12.x,可以使用scala.tools.nsc.interpreter.ILoop嵌入 Scala REPL。Scala 2.13.x scala.tools.nsc.interpreter.ILoop已被删除。如何嵌入 Scala 2.13.x REPL?

4

1 回答 1

2

尝试添加scala-compiler依赖

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

之后,例如,以下编译

import scala.tools.nsc.interpreter.shell.{ILoop, ShellConfig}
import scala.tools.nsc._

object EmbeddedREPL extend App {
  val settings = new Settings {
    usejavacp.value = true
    deprecation.value = true
  }
  val config = ShellConfig(settings)
  new ILoop(config).run(settings)
}
于 2020-01-18T17:58:49.860 回答