Annotation Type Option


  • @Retention(RUNTIME)
    @Target({METHOD,FIELD})
    @Inherited
    public @interface Option

    Marks a property of a Task as being configurable from the command-line.

    This annotation should be attached to a field or a setter method. When attached to a field, option() will use the name of the field by default. When attached to a method, option() must be specified.

    An option may have one of the following types:

    • boolean, Boolean, or Property<Boolean>
    • Double or Property<Double>
    • Integer or Property<Integer>
    • Long or Property<Long>
    • String or Property<String>
    • an enum type or Property<T> of an enum type
    • List<T> of type Double, Integer, Long, String, or an enum type
    • ListProperty<T> and SetProperty<T> of same type as List<T>
    • DirectoryProperty or RegularFileProperty

    Note: Multiple @Options with the same names are disallowed on different methods/fields. Methods with the same signature (i.e. the same name, return type, and parameter types) are allowed to use equal or unequal option names.

    When the option names are equal, the description and method linked to the option will be the one in the base class (if present), followed by super-classes, and finally interfaces, in an unspecified order.

    When the option names are unequal, the order described above is used when setting the option's value. If the base class has an option with the name "foo" and an interface has an option with the name "bar", the option "foo" will have precedence over the option "bar" and setting both will result in the value of "foo".

    Depending on this behavior is discouraged. It is only in place to allow legacy migration to interface options.

    Since:
    4.6
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String description
      The description of this option.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.String option
      The option to map to this property.
    • Element Detail

      • description

        java.lang.String description
        The description of this option.
        Returns:
        The description.
      • option

        java.lang.String option
        The option to map to this property. Required when annotating a method. May be omitted when annotating a field in which case the field's name will be used.
        Returns:
        The option.
        Default:
        ""