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?
Gradle supports version 1.6. 0 of Zinc and above. The Zinc compiler itself needs a compatible version of scala-library that may be different from the version required by your application. Gradle takes care of specifying a compatible version of scala-library for you.
Gradle is a build tool that can be used easily with a large number of programming languages including Scala. With it you can easily define your builds for Groovy or Kotlin, which enables for a high degree of customization.
There are two general types of plugins in Gradle, binary plugins and script plugins.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With