# Optional

@Documented
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = [ElementType.METHOD, ElementType.FIELD])
annotation class Optional(source)

Marks a task property as optional. This means that a value does not have to be specified for the property, but any value specified must meet the validation constraints for the property.

This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored.

This annotation must be combined with one of the following annotations.

- org.gradle.api.tasks.Input
- org.gradle.api.tasks.InputFile
- org.gradle.api.tasks.InputDirectory
- org.gradle.api.tasks.InputFiles
- org.gradle.api.tasks.Nested
- org.gradle.api.tasks.OutputFile
- org.gradle.api.tasks.OutputFiles
- org.gradle.api.tasks.OutputDirectory
- org.gradle.api.tasks.OutputDirectories
- org.gradle.api.services.ServiceReference

Using `@Optional` alone, without an accompanying input or output annotation, is a validation error. If you want to express that the property should not be an input or output, you should mark it with Internal which implies optionality.

## Functions

annotationType
Link copied to clipboard
abstract fun annotationType(): Class<out Annotation>
equals
Link copied to clipboard
abstract fun equals(p: Any): Boolean
hashCode
Link copied to clipboard
abstract fun hashCode(): Int
toString
Link copied to clipboard
abstract fun toString(): String