I have block like this one:
task print() {
doLast {
println("stop-1")
println(getJavaVersion())
println("stop-3")
}
}
def getJavaVersion() {
def out = new ByteArrayOutputStream()
exec {
workingDir 'C:/Program Files/Java/jdk1.7.0_80/bin'
commandLine 'cmd', '/c', 'java', '-version'
standardOutput = out
}
println 'stop-2'
return out.toString()
}
And I would expect that the output will be printed inside doLast
block of print
task, but it's printed just after exec
block.
This is the output:
Executing tasks: [print]
Parallel execution with configuration on demand is an incubating feature.
> Task :gcUnicorn-core:print
stop-1
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
stop-2
stop-3
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
As you can see, the output stream is empty.
I went trough Gradle's documentation and many examples I found, but have no luck to solve it.
Gradle: 4.10.2, Windows: 7, jdk1.8.0_192
Thank you for any advice.