Exec task and killing processes?

I’m looking at integrating Grunt with Gradle by using the exec task.

Basically I’m trying to call this from Gradle: cmd /c grunt --no-color watch

If I run the above command it runs node.exe on my machine. As this Grunt task watches for particular file changes the process will not end. As soon as I hit Ctrl-C the command ends and also the node process is killed automatically.

When I run something similar from Gradle using the exec task:

task grunt(type: Exec) {

commandLine = [“cmd”, “/c”, “grunt”, “–no-color”, “watch”] }

I can run the programm successfully. The Gradle task keeps running as the actual Grunt task is doing that as well.

Now the problem arises when I Ctrl-C the running Gradle task. Gradle stops it task, however the node process keeps running…

Any ideas if there is a way to kill it?

I’m running into essentially the same issue. I’m experimenting with using gradle as a wrapper around some other build tools during a migration process, and I’m having gradle actually invoke ant using exec { … }. If I CTRL-C the gradle process, on Windows, the ant process continues to run but with its output going into a black hole. On Linux, where CTRL-C sends SIGINT to the process group, both gradle and the ant process terminate.

It’s worth noting that running ant from ant in this particular way exhibits the same behavior.

<project>
  <target name="build">
    <exec executable="cmd">
      <arg value="/c"/>
      <arg value="ant"/>
      <arg value="-f"/>
      <arg value="build/build.xml"/>
      <arg value="dev"/>
    </exec>
  </target>
</project>

Any suggestions on the best way to achieve this?

No way to do this from within Gradle currently. You’ll have to use ProcessBuilder to launch the process and then you can use destroy().