# Annotation Type ServiceReference

@Documented @Retention(RUNTIME) @Target({METHOD,FIELD}) public @interface ServiceReference

Marks a task property as being a holder to a `BuildService`.

When you annotate a shared build service property with this annotation, there is no need to explicitly declare the association between the task and the service; also, if you provide a service name to the annotation, and a shared build service is registered with that name, it will be automatically assigned to the property when the task is created.

It is an error to apply this annotation to a property whose type is not a subtype of `BuildService`.

Since:
  8.0

- ## Optional Element Summary

  Optional Elements
  Modifier and Type
  Optional Element
  Description
  `String`
  `value`
  The optional name of the service which the annotated element references.

- ## Element Details

  - ### value

    String value

    The optional name of the service which the annotated element references.

    In case a service name is provided, if a shared build service is registered with that name, a provider to the service will be automatically assigned to the property.

    If a shared build service with the specified name is not found, and no value or convention is explicitly set on the property:

    - if the property is optional, an exception will only occur if an attempt is made to obtain the value of the property (see `Provider.get()`);
    - if the property is mandatory, before the task starts executing, a validation error will be issued.
    See Also:
      - `Optional`
      - `Provider.get()`
    Default:
      `""`