Edit: Improved description to reference the more generic solution (build cancel event) as oppose to the specific usage of this feature (Ctrl-D) explained by Gary's comment.
Expected Behavior
When JavaExec task waits for the completion of the Java application, it should support cancel event and terminate the Java application only. This exposes a deterministic build cancellation to Java shutdown hook execution delay to the user as well as avoid killing a perfectly healthy daemon. It would also be possible to support continuous mode for any JavaExec task.
Current Behavior
JavaExec doesn't support cancel event. The only way to cancel an application ran through that task is to send a Ctrl-C which will cause the daemon to exit as the JavaExec task doesn't return:
- There is a, up to, 10 seconds delay between Ctrl-C and the execution of the shutdown hook in the Java application
- The
System.{out|err} output of the Java application isn't piped to the console.
Context
Initial discussion in #1109
Steps to Reproduce (for bugs)
build.gradle:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Runner'
src/main/java/Runner.java
import java.io.File;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
public class Runner {
public static void main(String[] args) throws Exception {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Clean shutdown");
}));
File lock = new File("LOCK" + new Random().nextInt(20));
lock.createNewFile();
lock.deleteOnExit();
System.out.println("Created lock");
new CompletableFuture<Void>().get();
}
}
Edit: Improved description to reference the more generic solution (build cancel event) as oppose to the specific usage of this feature (Ctrl-D) explained by Gary's comment.
Expected Behavior
When
JavaExectask waits for the completion of the Java application, it should support cancel event and terminate the Java application only. This exposes a deterministic build cancellation to Java shutdown hook execution delay to the user as well as avoid killing a perfectly healthy daemon. It would also be possible to support continuous mode for anyJavaExectask.Current Behavior
JavaExecdoesn't support cancel event. The only way to cancel an application ran through that task is to send a Ctrl-C which will cause the daemon to exit as theJavaExectask doesn't return:System.{out|err}output of the Java application isn't piped to the console.Context
Initial discussion in #1109
Steps to Reproduce (for bugs)
build.gradle:
src/main/java/Runner.java