scalascala-replscala-2.13

Embedding scala 2.13.x REPL


For Scala 2.12.x one could use scala.tools.nsc.interpreter.ILoop to embed the Scala REPL. With Scala 2.13.x scala.tools.nsc.interpreter.ILoop has been removed. How could one embed the Scala 2.13.x REPL?


Solution

  • Try adding scala-compiler dependency

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

    after which, for example, the following compiles

    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)
    }