Scala REPL在Gradle中 [英] Scala REPL in Gradle

查看:96
本文介绍了Scala REPL在Gradle中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle的scala集成不提供REPL功能。如何使用适当的类路径从Gradle运行Scala REPL?

解决方案

最小 build.gradle

  apply plugin:'scala'

repositories {
mavenCentral()
}

依赖项{
compileorg.scala-lang:scala-library:2.11.7
compileorg.scala-lang :scala-compiler:2.11.7


任务repl(类型:JavaExec){
main =scala.tools.nsc.MainGenericRunner
classpath = sourceSets.main.runtimeClasspath
standardInput System.in
args'-usejavacp'
}

感谢这个回答,解释如何使用standardInput引导stdin,并让REPL使用正确的类路径带有参数。

请注意, scala-compiler 库是一个依赖项。这就是找到 scala.tools.nsc.MainGenericRunner 的地方。



在控制台中需要多个选项运行REPL:




  • - no-daemon ,如果你正在使用Gradle守护进程。目前,如果从守护进程运行,REPL不响应击键。


  • - console plain 。一个流行的,但低级的替代方案是 - 安静。如果没有这些选项之一运行,REPL的提示就会被Gradle的进度报告所污染。 - console plain 具有调整readline行为的好处,因此 rlwrap 是不必要的。




运行REPL的完整命令是 gradle repl --console plain --no-daemon ,所以在shell中创建一个别名是有道理的。


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?

解决方案

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.

这篇关于Scala REPL在Gradle中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆