I am trying to execute a command with gradle with the below task:
task stopServer(dependsOn: war, type: Exec) << {
commandLine \'pkill -9 tomcat\'
}
>
Here is another solution that works well for the same error if you have a standalone exec task that you want to run from the commandline but do not want to run in Android Studio as part of your build.
This will always run the configuration of "myExecTask" but will only execute doMyExecTask when it is explicitly run via "gradle myExecTask"
/**
* Actually run exec task in doLast phase
*/
task doMyExecTask << {
def hasProperties = project.hasProperty('SOME_PROPERTY');
if (hasProperties) {
myExecTask.commandLine "echo", "$SOME_PROPERTY"
} else {
println "ERROR: Unable to run task. Missing properties."
}
}
/**
* Configure exec task, this always runs
*/
task myExecTask(type: Exec) {
dependsOn doMyExecTask
workingDir 'path/to/executable'
}