Command line options for tasks

I would like to create a task with some additional options. org.gradle.api.internal.tasks.options.Option annotation seems to be used internally by gradle to achieve this. I found this topic in old forum Expose the org.gradle.api.internal.tasks.options.Option annotation for use in user tasks , is there any plan to make this annotation available to user tasks?

1 Like

We want to open up something like this, but have no concrete plans or schedule to do this.

And is it possible to use it now? even thought it’s internal api? can I get it on the classpath of buildscript? thx

It’s possible to use @Option right now. You’d just have to import the class into your build script or custom task class (depending on where you decide to use it).

import org.gradle.api.internal.tasks.option.Option;

Keep in that the class is an internal API and might change package, name, behavior or go away with future versions of Gradle.

Would you have an example on how exactly use Option to make a task put into build.gradle read options from the command line?

Here’s an example from one of Gradle’s own integration tests:

import org.gradle.api.internal.tasks.options.Option
import org.gradle.api.internal.tasks.options.OptionValues

    task hello(type: CustomTask)

class CustomTask extends DefaultTask {
    void doSomething() {

    @Option(option = "stringValue", description = "Configures a string value in CustomTask.")
    public void setStringValue(String value) {

    public List<String> possibleValues(){
        return Arrays.asList("optionA", "optionB", "optionC", "$path")

Why not making @option public/not-internal?

There was a PR for making it public but the contributor dropped off due to lack of time. Feel free to pick it up again. There’s nothing speaking against making it public per-se.