I have a Gradle project composed of several sub projects. I just created a new one to add support for an interactive Groovy shell that I would like to run with:
gradle console
or
gradle console:run
So my new console
module's build.gradle file is the following:
apply plugin: 'groovy'
apply plugin:'application'
mainClassName = 'org.codehaus.groovy.tools.shell.Main'
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.2.2'
compile 'org.fusesource.jansi:jansi:1.11'
compile 'commons-cli:commons-cli:1.2'
compile 'jline:jline:2.11'
compile project(':my-module')
}
task(console, dependsOn: 'classes', type: JavaExec) {
main = 'org.codehaus.groovy.tools.shell.Main'
classpath = sourceSets.main.runtimeClasspath
}
However, when I run gradle :console:run
or gradle console
I get something like:
:console:run
Groovy Shell (2.2.2, JVM: 1.6.0_45)
Type 'help' or '\h' for help.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000>
BUILD SUCCESSFUL
Total time: 4.529 secs
giovanni@mylaptop:~/Projects/my-project$
So the interactive shell seems to start but it exits right away.
Am I doing something wrong?
EDIT: Added the following to the build.gradle file:
run.standardInput = System.in
Now the standard input gets read from the input stream (thanks to the comments).
However, Gradle seems to get stuck on this:
Groovy Shell (2.2.2, JVM: 1.6.0_45)
Type 'help' or '\h' for help.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
groovy:000>
> Building 88% > :console:run
And no input gets accepted. Even this leads to the same thing:
gradle --no-daemon console:run
UPDATE 2018:
Dylons accepted answer don't seem to work anymore, ./gradlew console
exits immediately:
$ ./gradlew console
Configure project : The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead. at build_8qb2gvs00xed46ejq1p63fo92.run(/home/jhe052/eclipse-workspace/QuinCe/build.gradle:118) (Run with --stacktrace to get the full stack trace of this deprecation warning.)
BUILD SUCCESSFUL in 3s 3 actionable tasks: 1 executed, 2 up-to-date
Replacing the leftShift (<<) with doLast gets rid of the deprecated message but with the same result. Version info:
$ ./gradlew --version
Gradle 4.4.1
Build time: 2017-12-20 15:45:23 UTC Revision: 10ed9dc355dc39f6307cc98fbd8cea314bdd381c
Groovy: 2.4.12 Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017 JVM: 1.8.0_151 (Oracle Corporation 25.151-b12) OS: Linux 4.13.0-32-generic amd64