Scala REPL in Gradle

六眼飞鱼酱① 提交于 2019-11-29 17:47:11

问题


At the moment Gradle's scala integration does not offer REPL functionality. How to ergonomically run a Scala REPL from Gradle with the appropriate classpath?


回答1:


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.



来源:https://stackoverflow.com/questions/35632085/scala-repl-in-gradle

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