Gradle Version: 3.0
Operating System: OS X 10.11.6
When using gradle with the -Dorg.gradle.jvmargs
option to pass arguments to the JVM, gradle can’t be run in the background unless standard input is set to /dev/null
.
I created a trivial build.gradle
:
task hello {
doLast {
println "Sleeping..."
100.times {
println "Counting..."
sleep 1000
}
println "task2"
}
}
If I run gradle
without passing the -Dorg.gradle.jvmargs
option, it works as expected.
$ gradle --no-daemon hello >out.log 2>&1 & tail -f out.log
[1] 67218
:hello
Sleeping...
Counting...
Counting...
Counting...
Counting...
Counting...
Counting...
Counting...
^C
$ jobs
[1]+ Running gradle --no-daemon hello > out.log 2>&1 &
$ kill %1
[1]+ Exit 143 gradle --no-daemon hello > out.log 2>&1
However, if I pass an argument to the JVM using the -Dopg.gradle.jvmargs
, you can’t background gradle.
$ gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello >out.log 2>&1 & tail -f out.log
[1] 67311
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.0/userguide/gradle_daemon.html.
^C
[1]+ Stopped gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1
$ jobs
[1]+ Stopped gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1
$ bg
[1]+ gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1 &
[1]+ Stopped gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1
$ bg
[1]+ gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1 &
[1]+ Stopped gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1
$ bg
[1]+ gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1 &
[1]+ Stopped gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello > out.log 2>&1
At this point, gradle can’t be put in the background.
If I redirect stdin however, it works as expected:
$ gradle -Dorg.gradle.jvmargs=-Xms256m --no-daemon hello >out.log 2>&1 </dev/null & tail -f out.log
[2] 67483
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.0/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
:hello
Sleeping...
Counting...
Counting...
Counting...
Counting...
^C
So it seems to me that the original gradle process is blocking on stdin somehow.