ScalaConsole with Gradle 02 Jul 2013
The usual build tool for Scala is SBT, but I’ve been trying to stay consistent with Gradle builds. Of course, the most lacking feature is a decent REPL for manipulating the main/test classes, and there appear to be two possible solutions to this problem.
ScalaConsole in the Gradle scala plugin
The ScalaBasePlugin for Gradle defines the
scalaTestConsole tasks, which aren’t widely used (or documented) due to known issues. In particular, you have to make a few changes before the feature is usable. In order the fix the
:scalaConsole Error: Could not find or load main class scala.tools.nsc.MainGenericRunner
error, the scala-compiler must be added as a runtime dependency. In addition, the task dependencies and classpaths must be changed, as in the gist below.
However, you’ll still experience the problem of overlaying the Gradle build output on top of the REPL, unless you use the -q/–quiet switch. Many thanks to Tim Vergenz for pointing this out.
$ gradle scalaConsole -q Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_15). Type in expressions to have them evaluated. Type :help for more information. scala> var list = List("Lisp-ity List") list: List[String] = List(Lisp-ity List)
No longer actively developed, ScalaConsole is a Swing application that opens a REPL in a new window. Still a few changes necessary to add the working directories to the classpath: