Gradle exec commandLine doesn't work for me
I'm 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 exited with a non-zero return code, but if I copy the command and run it in a bash terminal, it works flawlessly.
So what am I doing wrong?
Hello,
source to share
There are two problems with this code: first, the call exec
happens outside of the task ( doLast { ... }
). The result exec
is called for every call to the assembly (even when typed gradle help
) during the assembly configuration phase. Second, it commandLine
takes a list of command line arguments, not a single line.
It is almost always better to use the problem type than the corresponding method, so this becomes:
task deploy(type: Exec) {
dependsOn jar
commandLine "javafxpackager", "-deploy", "-native", ...
}
To see how to set up a specific task (type) install the Gradle Build Language Link .
source to share