How can I start an interactive Clojure REPL as a Gradle task?

I’m using Gradle + the Clojuresque plugin for a large and complicated project. It would be desirable to be able to type “gradle :subproject:repl” and have the REPL fired up with all dependencies of “:subproject” on the classpath.

So far I have this:

task repl(type: JavaExec) {
        group "Other"
        description "Launches a Clojure REPL with the ${project} testCompile classpath"
          classpath configurations.testCompile
        classpath sourceSets.main.clojure.srcDirs
        classpath sourceSets.test.clojure.srcDirs
        main "clojure.main"

That builds the right command and the REPL starts, then immediately shuts down:

  Starting process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/bin/java''. Working directory: /Users/hlship/workspaces/annadale/nexus/core-services Command: /Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -cp /Users/hlship/workspaces/annadale/nexus/util/logging/build/l  ...  f9f135bf4/jackson-dataformat-smile-2.0.4.jar:/Users/hlship/workspaces/annadale/nexus/core-services/src/main/clojure:/Users/hlship/workspaces/annadale/nexus/core-services/src/test/clojure clojure.main  An attempt to initialize for well behaving parent process finished.  Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/bin/java''  Clojure 1.4.0  user=>

Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_12.jdk/Contents/Home/bin/java'' finished with exit value 0 (state: SUCCEEDED)


Any advice on how to, say, set JavaExec.inputStream to read from the console?

‘standardInput’, as used for the ‘scalaConsole’ task, should get you a bit further. What’s still missing though is a way to suppress the Gradle status line, as well as true console support (arrow keys etc.).

That helps but its not exactly usable. It would be nice if JavaExec had an option for just this purpose.

Sure. Better console support is in the pipeline, but I can’t say which release it will be scheduled for.

1 Like