How to not have Gradle quit Scala's REPL immediately?

余生长醉 提交于 2019-12-10 17:54:23

问题


These simple lines in build.gradle expose a repl task that would ideally fire up a scala REPL. Fire up and keep alive that is. After the repl loads, it immediately receives a :quit command and exits.

Important parts of build.gradle:

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
}

Launching the REPL:

% gradle repl
:compileJava UP-TO-DATE
:compileScala UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:repl
Welcome to Scala version 2.11.7 (OpenJDK Server VM, Java 1.7.0_91).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :quit

BUILD SUCCESSFUL

Total time: 31.177 secs

REPL quits automatically immediately after launching. How to not have the REPL quit immediately?


回答1:


You also need to redirect console input to your javaexec java process. Try adding standardInput System.in to your task definition. In my case, I also found it necessary to add args '-userjavacp'.

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

and finally running gradle with the -q option suppresses the gradle progress prompts giving me a cleaner scala repl.



来源:https://stackoverflow.com/questions/35614412/how-to-not-have-gradle-quit-scalas-repl-immediately

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