Why can't I start java directly using Gradles Exec-task?

Viewed 95

I wanted to start java from a gradle build-script using the Exec-task (https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html)

Using the command java -version directly does not work.

task runApp(type:Exec) {
  commandLine 'java -version'
}

When copying the command to a file named script.sh, it is executed

task runApp(type:Exec) {
  commandLine './script.sh'
}

But why? Shouldn't commandLine 'java -version' work as well?

1 Answers
Related