{"action":"created","issue":{"url":"https://api.github.com/repos/gradle/gradle/issues/2402","repository_url":"https://api.github.com/repos/gradle/gradle","labels_url":"https://api.github.com/repos/gradle/gradle/issues/2402/labels{/name}","comments_url":"https://api.github.com/repos/gradle/gradle/issues/2402/comments","events_url":"https://api.github.com/repos/gradle/gradle/issues/2402/events","html_url":"https://github.com/gradle/gradle/issues/2402","id":241067601,"number":2402,"title":"Public API for defining and parsing custom command line options for tasks","user":{"login":"bmuschko","id":440872,"avatar_url":"https://avatars2.githubusercontent.com/u/440872?v=4","gravatar_id":"","url":"https://api.github.com/users/bmuschko","html_url":"https://github.com/bmuschko","followers_url":"https://api.github.com/users/bmuschko/followers","following_url":"https://api.github.com/users/bmuschko/following{/other_user}","gists_url":"https://api.github.com/users/bmuschko/gists{/gist_id}","starred_url":"https://api.github.com/users/bmuschko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmuschko/subscriptions","organizations_url":"https://api.github.com/users/bmuschko/orgs","repos_url":"https://api.github.com/users/bmuschko/repos","events_url":"https://api.github.com/users/bmuschko/events{/privacy}","received_events_url":"https://api.github.com/users/bmuschko/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":536840723,"url":"https://api.github.com/repos/gradle/gradle/labels/in:cli","name":"in:cli","color":"d4c5f9","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":1,"created_at":"2017-07-06T19:54:49Z","updated_at":"2017-07-18T19:48:30Z","closed_at":null,"body":"Gradle defines an internal API for defining custom command line options for tasks in the package `org.gradle.api.internal.tasks.options`. Many users are interested in using the feature in their plugins.\r\n\r\n### Expected Behavior\r\n\r\nTasks can define custom command line options for exposed properties with the help of a public API. The follow example demonstrates how the use of `@Option` could look like for a task that comes with the [Spring Boot plugin](https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html).\r\n\r\n```\r\ntask bootRun(type: BootRun)\r\n\r\npublic class BootRun extends DefaultTask {\r\n    private String bootRunArg;\r\n    private String bootRunJvmArg;\r\n    private String profile;\r\n    private List<String> multiValues;\r\n\r\n    @Option(option = \"bootRunArg\", description = \"The Spring Boot run arguments.\")\r\n    public void setBootRunArg(String bootRunArg) {\r\n        this.bootRunArg = bootRunArg;\r\n    }\r\n\r\n    @Option(option = \"bootRunJvmArg\", description = \"The Spring Boot JVM arguments.\")\r\n    public void setBootRunJvmArg(String bootRunJvmArg) {\r\n        this.bootRunJvmArg = bootRunJvmArg;\r\n    }\r\n\r\n    @Option(option = \"profile\", description = \"The active Spring profile.\")\r\n    public void setProfile(String profile) {\r\n        this.profile = profile;\r\n    }\r\n    \r\n    @Option(option = \"multiValues\", description = \"A multi-value String.\")\r\n    public void setMultiValue(List<String> multiValues) {\r\n        this.multiValues = multiValues;\r\n    }\r\n    \r\n    @TaskAction\r\n    public void run() {\r\n        System.out.println(\"bootRunArg: \" + bootRunArg);\r\n        System.out.println(\"bootRunJvmArg: \" + bootRunJvmArg);\r\n        System.out.println(\"profile: \" + profile);\r\n        System.out.println(\"multiValues: \" + multiValues);\r\n    }\r\n}\r\n```\r\n\r\nUsage from the command line:\r\n\r\n```\r\ngradle bootRun --multiValues=--spring.profiles.active=random --multiValues=--server.port=8080 --bootRunArg=--spring.profiles.active=random\r\n```\r\n\r\n### Current Behavior\r\n\r\nUsers have to use an internal API to define custom command line options for tasks. Internal APIs can change at any time and break published, external plugins.\r\n\r\n### Context\r\n\r\n- https://discuss.gradle.org/t/command-line-options-for-tasks/9686/7\r\n- https://discuss.gradle.org/t/expose-the-org-gradle-api-internal-tasks-options-option-annotation-for-use-in-user-tasks/319\r\n- https://discuss.gradle.org/t/parameterizing-tasks-with-option-in-org-gradle-tooling-gradleconnector/6343/3\r\n- https://discuss.gradle.org/t/org-gradle-api-internal-tasks-options-option-not-available-for-own-tasks/21335\r\n"},"comment":{"url":"https://api.github.com/repos/gradle/gradle/issues/comments/316177130","html_url":"https://github.com/gradle/gradle/issues/2402#issuecomment-316177130","issue_url":"https://api.github.com/repos/gradle/gradle/issues/2402","id":316177130,"user":{"login":"wilkinsona","id":914682,"avatar_url":"https://avatars3.githubusercontent.com/u/914682?v=4","gravatar_id":"","url":"https://api.github.com/users/wilkinsona","html_url":"https://github.com/wilkinsona","followers_url":"https://api.github.com/users/wilkinsona/followers","following_url":"https://api.github.com/users/wilkinsona/following{/other_user}","gists_url":"https://api.github.com/users/wilkinsona/gists{/gist_id}","starred_url":"https://api.github.com/users/wilkinsona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilkinsona/subscriptions","organizations_url":"https://api.github.com/users/wilkinsona/orgs","repos_url":"https://api.github.com/users/wilkinsona/repos","events_url":"https://api.github.com/users/wilkinsona/events{/privacy}","received_events_url":"https://api.github.com/users/wilkinsona/received_events","type":"User","site_admin":false},"created_at":"2017-07-18T19:48:30Z","updated_at":"2017-07-18T19:48:30Z","body":"This would be a welcome new feature for the users of Spring Boot's Gradle plugin. We have a long-standing [enhancement request](https://github.com/spring-projects/spring-boot/issues/1176) that led to me discussing this with @bmuschko at the recent Summit."}}
{"actor":{"display_login":"wilkinsona"}}