Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In gradle tasks of type Exec, why do commandLine and executable behave differently?

Tags:

gradle

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?

like image 758
matt Avatar asked Apr 02 '13 23:04

matt


People also ask

How do you pass command line arguments in Gradle?

Types of Input Arguments When we want to pass input arguments from the Gradle CLI, we have two choices: setting system properties with the -D flag. setting project properties with the -P flag.

How does Gradle task work?

Gradle has different phases, when it comes to working with the tasks. First of all, there is a configuration phase, where the code, which is specified directly in a task's closure, is executed. The configuration block is executed for every available task and not only, for those tasks, which are later actually executed.

What does Gradle use to determine the order in which tasks can be?

Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.

Which are the tasks are performed by Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.


1 Answers

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.

like image 187
Hiery Nomus Avatar answered Sep 21 '22 11:09

Hiery Nomus