Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle exec commandLine not working for me

Tags:

gradle

exec

I am trying to run an executable with arguments from gradle:

task deploy(dependsOn: jar) {
    exec {
        commandLine "javafxpackager -deploy -native -outdir ${deployDirName} -outfile ${jarBaseName} -srcfiles ./${project.buildDir}/${project.libsDirName}/${jarBaseName}-${project.version}.jar -appclass ${mainClass} -name ${jarBaseName} -title '${project.description}'"
    }
}

Gradle complains that the process ended up with non-zero return code, but if I copy the command and run it within bash terminal, it works flawlessly.

So what am I doing wrong?

Regards,

like image 583
adragomir Avatar asked Oct 15 '25 01:10

adragomir


1 Answers

There are two problems with this code: First, the exec call happens outside a task action (doLast { ... }). As a result, exec will get called for every single build invocation (even when typing gradle help), in the configuration phase of the build. Second, commandLine accepts a list of command line arguments, not a single string.

It's almost always better to use a task type than the corresponding method, so this becomes:

task deploy(type: Exec) {
    dependsOn jar
    commandLine "javafxpackager", "-deploy",  "-native", ...
}

To find out how to configure a particular task (type), check the Gradle Build Language Reference.

like image 181
Peter Niederwieser Avatar answered Oct 18 '25 10:10

Peter Niederwieser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!