Reputation: 815
Does anyone know why in tasks of type Exec
commandline
and executable
behave differently in terms of inheriting environment vars?
For example, I cannot run this Task because Gradle fails to find ruby from my environment:
task checkRubyVersionCommandLine(type: Exec) {
commandLine 'ruby -v'
}
Yet this works fine:
task checkRubyVersionExecute(type: Exec) {
executable = 'ruby'
args = ['-v']
}
What is commandLine
for, or how can I get it to pick up the variables from the shell it is executed from? Why does executable
just work?
Upvotes: 34
Views: 57241
Reputation: 17769
When using the commandLine
, you need to split the string on spaces, else the executable becomes ruby -v
, instead of ruby
.
So try this instead:
task checkRubyVersionExecute(type: Exec) {
commandLine 'ruby', '-v'
}
See the code here to see how the Exec task handles this.
Upvotes: 51