Run finalizedBy when task is interrupted (ctrl-c) - continued from old forum

Continuing the discussion from Run finalizedBy when task is interrupted (ctrl-c):

I have this same problem. Catching SIGTERM should be possible…the entire purpose of a finalizeBy is eg shutting down a test server, so leaving it up when the user wants to just cancel the build trappy behavior!

The long term plan is to use a different signal to ‘cancel’ the build (see the discussion here Ctrl-c during running build also kills daemon), so finalizers have a chance to run. Part of the reason we haven’t provided something like this sooner is that it breaks builds that rely on reading from the Console themselves.

We also want to make it so something like a long running test server is more richly modeled (sort of like what’s happening with Play’s local dev server), so Gradle would know how to start/stop it across build invocations.

The short term workaround might be to provide a “stopAllTestServers” task that can be run if a build is canceled mid-test or make the start task smart enough to recover after an incomplete stop.