本文介绍了如何不让Gradle立即退出Scala的REPL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

build.gradle 中的这些简单行暴露了一个理想情况下会启动一个scala REPL的 repl 任务。开火并保持活力。在repl加载后,它会立即收到:quit命令并退出。

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.

build.gradle 的重要部分:

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
}

启动REPL :

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在启动后立即自动退出。如何不立即退出REPL?

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

推荐答案

您还需要将控制台输入重定向到javaexec java进程。尝试将 standardInput System.in 添加到您的任务定义中。就我而言,我还发现有必要添加 args'-userjavacp'

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

,最后用 -q 选项运行gradle可以抑制gradle进度提示,给我一个更清晰的scala repl。

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

这篇关于如何不让Gradle立即退出Scala的REPL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 18:00