{"action":"created","issue":{"url":"https://api.github.com/repos/gradle/gradle/issues/1128","repository_url":"https://api.github.com/repos/gradle/gradle","labels_url":"https://api.github.com/repos/gradle/gradle/issues/1128/labels{/name}","comments_url":"https://api.github.com/repos/gradle/gradle/issues/1128/comments","events_url":"https://api.github.com/repos/gradle/gradle/issues/1128/events","html_url":"https://github.com/gradle/gradle/issues/1128","id":199540310,"number":1128,"title":"Support Build Cancellation in `JavaExec` Task","user":{"login":"lacasseio","id":22181740,"avatar_url":"https://avatars2.githubusercontent.com/u/22181740?v=4","gravatar_id":"","url":"https://api.github.com/users/lacasseio","html_url":"https://github.com/lacasseio","followers_url":"https://api.github.com/users/lacasseio/followers","following_url":"https://api.github.com/users/lacasseio/following{/other_user}","gists_url":"https://api.github.com/users/lacasseio/gists{/gist_id}","starred_url":"https://api.github.com/users/lacasseio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lacasseio/subscriptions","organizations_url":"https://api.github.com/users/lacasseio/orgs","repos_url":"https://api.github.com/users/lacasseio/repos","events_url":"https://api.github.com/users/lacasseio/events{/privacy}","received_events_url":"https://api.github.com/users/lacasseio/received_events","type":"User","site_admin":false},"labels":[{"id":460356753,"url":"https://api.github.com/repos/gradle/gradle/labels/a:feature","name":"a:feature","color":"0e8a16","default":false},{"id":289469033,"url":"https://api.github.com/repos/gradle/gradle/labels/from:member","name":"from:member","color":"0052cc","default":false},{"id":285742270,"url":"https://api.github.com/repos/gradle/gradle/labels/in:core","name":"in:core","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-01-09T12:25:01Z","updated_at":"2017-09-17T17:40:30Z","closed_at":null,"author_association":"MEMBER","body":"_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](https://github.com/gradle/gradle/issues/1128#issuecomment-271299381)._\r\n\r\n### Expected Behavior\r\nWhen `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.\r\n\r\n### Current Behavior\r\n`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:\r\n1. There is a, up to, 10 seconds delay between Ctrl-C and the execution of the shutdown hook in the Java application\r\n2. The `System.{out|err}` output of the Java application isn't piped to the console.\r\n\r\n### Context\r\nInitial discussion in https://github.com/gradle/gradle/issues/1109\r\n\r\n### Steps to Reproduce (for bugs)\r\nbuild.gradle:\r\n```\r\napply plugin: 'java'\r\napply plugin: 'application'\r\n\r\nmainClassName = 'Runner'\r\n```\r\n\r\nsrc/main/java/Runner.java\r\n```\r\nimport java.io.File;\r\nimport java.util.Random;\r\nimport java.util.concurrent.CompletableFuture;\r\n\r\npublic class Runner {\r\n    public static void main(String[] args) throws Exception {\r\n        Runtime.getRuntime().addShutdownHook(new Thread(() -> {\r\n            System.out.println(\"Clean shutdown\");\r\n        }));\r\n        File lock = new File(\"LOCK\" + new Random().nextInt(20));\r\n        lock.createNewFile();\r\n        lock.deleteOnExit();\r\n        System.out.println(\"Created lock\");\r\n        new CompletableFuture<Void>().get();\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/gradle/gradle/issues/comments/330064896","html_url":"https://github.com/gradle/gradle/issues/1128#issuecomment-330064896","issue_url":"https://api.github.com/repos/gradle/gradle/issues/1128","id":330064896,"user":{"login":"fab1an","id":55547,"avatar_url":"https://avatars0.githubusercontent.com/u/55547?v=4","gravatar_id":"","url":"https://api.github.com/users/fab1an","html_url":"https://github.com/fab1an","followers_url":"https://api.github.com/users/fab1an/followers","following_url":"https://api.github.com/users/fab1an/following{/other_user}","gists_url":"https://api.github.com/users/fab1an/gists{/gist_id}","starred_url":"https://api.github.com/users/fab1an/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fab1an/subscriptions","organizations_url":"https://api.github.com/users/fab1an/orgs","repos_url":"https://api.github.com/users/fab1an/repos","events_url":"https://api.github.com/users/fab1an/events{/privacy}","received_events_url":"https://api.github.com/users/fab1an/received_events","type":"User","site_admin":false},"created_at":"2017-09-17T17:40:30Z","updated_at":"2017-09-17T17:40:30Z","author_association":"NONE","body":"I worked around that by putting the start in a shellscript like `./gradlew\nbuild && java -jar ...`\nThen call that script in IDEA and terminate it with the button.\n"}}
{"actor":{"display_login":"fab1an"}}