Scala REPL in Gradle

旧巷老猫 提交于 2019-11-30 12:42:12
Dominykas Mostauskis

Minimal build.gradle:

apply plugin: 'scala'

repositories{
  mavenCentral()
}

dependencies{
  compile "org.scala-lang:scala-library:2.11.7"
  compile "org.scala-lang:scala-compiler:2.11.7"
}

task repl(type:JavaExec) {
  main = "scala.tools.nsc.MainGenericRunner"
  classpath = sourceSets.main.runtimeClasspath
  standardInput System.in
  args '-usejavacp'
}

Credit to this answer for explaining how to direct stdin with standardInput and have REPL use the right classpath with args.

Notice the scala-compiler library is a dependency. That's where scala.tools.nsc.MainGenericRunner is found.

From the console a number of options are needed to run the REPL:

  • --no-daemon, if you are using a Gradle daemon. At the moment, the REPL does not respond to keystrokes if run from the daemon.

  • --console plain. A popular, but inferior alternative is --quiet. If run without one of these options, REPL's prompt is contaminated by Gradle's progress report. --console plain has the advantage that it also adjusts readline's behaviour so that rlwrap is unnecessary.

Full command to run the REPL is gradle repl --console plain --no-daemon, so creating an alias in your shell makes sense.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!