Package org.gradle.api.model

## Interface ObjectFactory

-     @Incubating
      public interface ObjectFactory

  A factory for creating various kinds of model objects.

  An instance of the factory can be injected into a task or plugin by annotating a public constructor or property getter method with `javax.inject.Inject`. It is also available via `Project.getObjects()`.

  Since:
    4.0

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DirectoryProperty` | `directoryProperty​()` | Creates a new `DirectoryProperty` that uses the project directory to resolve relative paths, if required.
    `RegularFileProperty` | `fileProperty​()` | Creates a new `RegularFileProperty` that uses the project directory to resolve relative paths, if required.
    `<T> ListProperty<T>` | `listProperty​(java.lang.Class<T> elementType)` | Creates a `ListProperty` implementation to hold a `List` of the given element type `T`.
    `<T extends Named> T` | `named​(java.lang.Class<T> type, java.lang.String name)` | Creates a simple immutable `Named` object of the given type and name.
    `<T> T` | `newInstance​(java.lang.Class<? extends T> type, java.lang.Object... parameters)` | Create a new instance of T, using `parameters` as the construction parameters.
    `<T> Property<T>` | `property​(java.lang.Class<T> valueType)` | Creates a `Property` implementation to hold values of the given type.
    `<T> SetProperty<T>` | `setProperty​(java.lang.Class<T> elementType)` | Creates a `SetProperty` implementation to hold a `Set` of the given element type `T`.
    `SourceDirectorySet` | `sourceDirectorySet​(java.lang.String name, java.lang.String displayName)` | Creates a `SourceDirectorySet`.

- - ### Method Detail

    - #### named

          <T extends Named> T named​(java.lang.Class<T> type,
                                    java.lang.String name)
                             throws ObjectInstantiationException

      Creates a simple immutable `Named` object of the given type and name.

      The given type can be an interface that extends `Named` or an abstract class that 'implements' `Named`. An abstract class, if provided:

      - Must provide a zero-args constructor that is not private.
      - Must not define or inherit any instance fields.
      - Should not provide an implementation for `Named.getName()` and should define this method as abstract. Any implementation will be overridden.
      - Must not define or inherit any other abstract methods.

      An interface, if provided, must not define or inherit any other methods.

      Objects created using this method are not decorated or extensible.

      Throws:
        `ObjectInstantiationException` - On failure to create the new instance.
      Since:
        4.0

    - #### newInstance

          <T> T newInstance​(java.lang.Class<? extends T> type,
                            java.lang.Object... parameters)
                     throws ObjectInstantiationException

      Create a new instance of T, using `parameters` as the construction parameters.

      The type must be a non-abstract class.

      Objects created using this method are decorated and extensible, meaning that they have DSL support mixed in and can be extended using the `extensions` property, similar to the `Project` object.

      An @Inject annotation is required on any constructor that accepts parameters because JSR-330 semantics for dependency injection are used. In addition to those parameters provided as an argument to this method, the following services are also available for injection:

      - `ObjectFactory`.
      - `ProjectLayout`.
      - `ProviderFactory`.
      Throws:
        `ObjectInstantiationException` - On failure to create the new instance.
      Since:
        4.2

    - #### sourceDirectorySet

          SourceDirectorySet sourceDirectorySet​(java.lang.String name,
                                                java.lang.String displayName)

      Creates a `SourceDirectorySet`.
      Parameters:
        `name` - A short name for the set.
        `displayName` - A human consumable display name for the set.
      Since:
        5.0

    - #### property

          <T> Property<T> property​(java.lang.Class<T> valueType)

      Creates a `Property` implementation to hold values of the given type. The property has no initial value.

      For certain types, there are more specialized property factory methods available:

      - For `List` properties, you should use `listProperty(Class)`.
      - For `Set` properties, you should use `setProperty(Class)`.
      - For `Directory` properties, you should use `directoryProperty()`.
      - For `RegularFile` properties, you should use `fileProperty()`.
      Parameters:
        `valueType` - The type of the property.
      Returns:
        The property. Never returns null.
      Since:
        4.3

    - #### listProperty

          <T> ListProperty<T> listProperty​(java.lang.Class<T> elementType)

      Creates a `ListProperty` implementation to hold a `List` of the given element type `T`. The property has no initial value.

      The implementation will return immutable `List` values from its query methods.

      Type Parameters:
        `T` - The type of element.
      Parameters:
        `elementType` - The type of element.
      Returns:
        The property. Never returns null;
      Since:
        4.3

    - #### setProperty

          <T> SetProperty<T> setProperty​(java.lang.Class<T> elementType)

      Creates a `SetProperty` implementation to hold a `Set` of the given element type `T`. The property has no initial value.

      The implementation will return immutable `Set` values from its query methods.

      Type Parameters:
        `T` - The type of element.
      Parameters:
        `elementType` - The type of element.
      Returns:
        The property. Never returns null;
      Since:
        4.5

    - #### directoryProperty

          DirectoryProperty directoryProperty​()

      Creates a new `DirectoryProperty` that uses the project directory to resolve relative paths, if required. The property has no initial value.
      Since:
        5.0

    - #### fileProperty

          RegularFileProperty fileProperty​()

      Creates a new `RegularFileProperty` that uses the project directory to resolve relative paths, if required. The property has no initial value.
      Since:
        5.0