Package org.gradle.api.tasks

# Interface TaskContainer

All Superinterfaces:
  `Collection<Task>`, `Configurable<NamedDomainObjectContainer<Task>>`, `DomainObjectCollection<Task>`, `DomainObjectSet<Task>`, `Iterable<Task>`, `NamedDomainObjectCollection<Task>`, `NamedDomainObjectContainer<Task>`, `NamedDomainObjectSet<Task>`, `PolymorphicDomainObjectContainer<Task>`, `Set<Task>`, `TaskCollection<Task>`

public interface TaskContainer extends TaskCollection<Task>, PolymorphicDomainObjectContainer<Task>

A `TaskContainer` is responsible for managing a set of `Task` instances.

You can obtain a `TaskContainer` instance by calling `Project.getTasks()`, or using the `tasks` property in your build script.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Task`
  `create(String name)`
  Deprecated.
  Use `register(String)` instead.
  `Task`
  `create(String name, Closure configureClosure)`
  Deprecated.
  Use `register(String, Action)` instead.
  `<T extends Task>
  T`
  `create(String name, Class<T> type)`
  Deprecated.
  Use `register(String, Class)` instead.
  `<T extends Task>
  T`
  `create(String name, Class<T> type, Object... constructorArgs)`
  Deprecated.
  Use `register(String, Class, Object...)` instead.
  `<T extends Task>
  T`
  `create(String name, Class<T> type, Action<? super T> configuration)`
  Deprecated.
  Use `register(String, Class, Action)` instead.
  `Task`
  `create(String name, Action<? super Task> configuration)`
  Deprecated.
  Use `register(String, Action)` instead.
  `Task`
  `create(Map<String,?> options)`
  Deprecated.
  Use `register(String, Action)` or `register(String, Class, Action)` instead.
  `Task`
  `create(Map<String,?> options, Closure configureClosure)`
  Deprecated.
  Use `register(String, Action)` instead.
  `@Nullable Task`
  `findByPath(String path)`
  Locates a task by path.
  `Task`
  `getByPath(String path)`
  Locates a task by path.
  `TaskProvider<Task>`
  `register(String name)`
  Defines a new task, which will be created when it is required.
  `<T extends Task>
  TaskProvider<T>`
  `register(String name, Class<T> type)`
  Defines a new task, which will be created when it is required.
  `<T extends Task>
  TaskProvider<T>`
  `register(String name, Class<T> type, Object... constructorArgs)`
  Defines a new task, which will be created when it is required passing the given arguments to the `@Inject`-annotated constructor.
  `<T extends Task>
  TaskProvider<T>`
  `register(String name, Class<T> type, Action<? super T> configurationAction)`
  Defines a new task, which will be created and configured when it is required.
  `TaskProvider<Task>`
  `register(String name, Action<? super Task> configurationAction)`
  Defines a new task, which will be created and configured when it is required.
  `Task`
  `replace(String name)`
  Creates a `Task` with the given name and adds it to this container, replacing any existing task with the same name.
  `<T extends Task>
  T`
  `replace(String name, Class<T> type)`
  Creates a `Task` with the given name and type, and adds it to this container, replacing any existing task of the same name.

  ### Methods inherited from interface java.util.Collection

  `parallelStream, removeIf, stream, toArray`

  ### Methods inherited from interface org.gradle.api.DomainObjectCollection

  `addAllLater, addLater, all, all, configureEach, disallowChanges, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectCollection

  `add, addAll, addRule, addRule, addRule, findByName, getAsMap, getByName, getCollectionSchema, getNamer, getNames, getRules`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectContainer

  `configure, maybeCreate`

  ### Methods inherited from interface org.gradle.api.NamedDomainObjectSet

  `findAll`

  ### Methods inherited from interface org.gradle.api.PolymorphicDomainObjectContainer

  `containerWithType, maybeCreate`

  ### Methods inherited from interface java.util.Set

  `add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, spliterator, toArray, toArray`

  ### Methods inherited from interface org.gradle.api.tasks.TaskCollection

  `getAt, getByName, getByName, matching, matching, named, named, named, named, named, whenTaskAdded, whenTaskAdded, withType`

- ## Method Details

  - ### findByPath

    @Nullable Task findByPath(String path)

    Locates a task by path. You can supply a task name, a relative path, or an absolute path. Relative paths are interpreted relative to the project for this container. This method returns null if no task with the given path exists.

    Parameters:
      `path` - the path of the task to be returned
    Returns:
      The task. Returns null if so such task exists.

  - ### getByPath

    Task getByPath(String path) throws UnknownTaskException

    Locates a task by path. You can supply a task name, a relative path, or an absolute path. Relative paths are interpreted relative to the project for this container. This method throws an exception if no task with the given path exists.

    Parameters:
      `path` - the path of the task to be returned
    Returns:
      The task. Never returns null
    Throws:
      `UnknownTaskException` - If no task with the given path exists.

  - ### create

    @Deprecated Task create(Map<String,?> options) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Action)` or `register(String, Class, Action)` instead. See documentation for more information.

    Creates a `Task` and adds it to this container. A map of creation options can be passed to this method to control how the task is created. The following options are available:

    Permitted map keys
    Option | Description | Default Value
    --- | --- | ---
    `"name"` | The name of the task to create. | None. Must be specified.
    `"type"` | The class of the task to create. | `DefaultTask`
    `"action"` | The closure or `Action` to execute when the task executes. See `Task.doFirst(Action)`. | `null`
    `"overwrite"` | Replace an existing task? | `false`
    `"dependsOn"` | The dependencies of the task. See here for more details. | `[]`
    `"group"` | The group of the task. | `null`
    `"description"` | The description of the task. | `null`
    `"constructorArgs"` | The arguments to pass to the task class constructor. | `null`

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    If a task with the given name already exists in this container and the `"overwrite"` option is not set to true, an exception is thrown.

    Parameters:
      `options` - The task creation options.
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
      `NullPointerException` - If any of the values in `"constructorArgs"` is null.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated Task create(Map<String,?> options, Closure configureClosure) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Action)` instead. See documentation for more information.

    Creates a `Task` adds it to this container. A map of creation options can be passed to this method to control how the task is created. See `create(java.util.Map)` for the list of options available. The given closure is used to configure the task before it is returned by this method.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Parameters:
      `options` - The task creation options.
      `configureClosure` - The closure to use to configure the task.
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated Task create(String name, Closure configureClosure) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Action)` instead. See documentation for more information.

    Creates a `Task` with the given name adds it to this container. The given closure is used to configure the task before it is returned by this method.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Specified by:
      `create` in interface `NamedDomainObjectContainer<Task>`
    Parameters:
      `name` - The name of the task to be created
      `configureClosure` - The closure to use to configure the task.
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated Task create(String name) throws InvalidUserDataException
    Deprecated.
    Use `register(String)` instead. See documentation for more information.

    Creates a `Task` with the given name and adds it to this container.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Specified by:
      `create` in interface `NamedDomainObjectContainer<Task>`
    Parameters:
      `name` - The name of the task to be created
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated <T extends Task> T create(String name, Class<T> type) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Class)` instead. See documentation for more information.

    Creates a `Task` with the given name and type, and adds it to this container.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Specified by:
      `create` in interface `PolymorphicDomainObjectContainer<Task>`
    Type Parameters:
      `T` - the type of the domain object to be created
    Parameters:
      `name` - The name of the task to be created.
      `type` - The type of task to create.
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated <T extends Task> T create(String name, Class<T> type, Object... constructorArgs) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Class, Object...)` instead. See documentation for more information.

    Creates a `Task` with the given name and type, passing the given arguments to the `@Inject`-annotated constructor, and adds it to this container. All values passed to the task constructor must be non-null; otherwise a `NullPointerException` will be thrown

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Parameters:
      `name` - The name of the task to be created.
      `type` - The type of task to create.
      `constructorArgs` - The arguments to pass to the task constructor
    Returns:
      The newly created task object
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
      `NullPointerException` - If any of the values in `constructorArgs` is null.
    Since:
      4.7
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated <T extends Task> T create(String name, Class<T> type, Action<? super T> configuration) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Class, Action)` instead. See documentation for more information.

    Creates a `Task` with the given name and type, configures it with the given action, and adds it to this container.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Specified by:
      `create` in interface `PolymorphicDomainObjectContainer<Task>`
    Type Parameters:
      `T` - the type of the domain object to be created
    Parameters:
      `name` - The name of the task to be created.
      `type` - The type of task to create.
      `configuration` - The action to configure the task with.
    Returns:
      The newly created task object.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### create

    @Deprecated Task create(String name, Action<? super Task> configuration) throws InvalidUserDataException
    Deprecated.
    Use `register(String, Action)` instead. See documentation for more information.

    Creates a `Task` with the given name and of type `DefaultTask`, configures it with the given action, and adds it to this container.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Specified by:
      `create` in interface `NamedDomainObjectContainer<Task>`
    Parameters:
      `name` - The name of the task to be created.
      `configuration` - The action to configure the task with.
    Returns:
      The newly created task object.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### register

    TaskProvider<Task> register(String name, Action<? super Task> configurationAction) throws InvalidUserDataException
    Defines a new task, which will be created and configured when it is required. A task is 'required' when the task is located using query methods such as `TaskCollection.getByName(java.lang.String)`, when the task is added to the task graph for execution or when `Provider.get()` is called on the return value of this method.

    It is generally more efficient to use this method instead of `NamedDomainObjectContainer.create(java.lang.String, org.gradle.api.Action)` or `create(java.lang.String)`, as those methods will eagerly create and configure the task, regardless of whether that task is required for the current build or not. This method, on the other hand, will defer creation and configuration until required.

    Specified by:
      `register` in interface `NamedDomainObjectContainer<Task>`
    Parameters:
      `name` - The name of the task.
      `configurationAction` - The action to run to configure the task. This action runs when the task is required.
    Returns:
      A `Provider` whose value will be the task, when queried.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    Since:
      4.9

  - ### register

    <T extends Task> TaskProvider<T> register(String name, Class<T> type, Action<? super T> configurationAction) throws InvalidUserDataException
    Defines a new task, which will be created and configured when it is required. A task is 'required' when the task is located using query methods such as `TaskCollection.getByName(java.lang.String)`, when the task is added to the task graph for execution or when `Provider.get()` is called on the return value of this method.

    It is generally more efficient to use this method instead of `create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `create(java.lang.String, java.lang.Class)`, as those methods will eagerly create and configure the task, regardless of whether that task is required for the current build or not. This method, on the other hand, will defer creation and configuration until required.

    Specified by:
      `register` in interface `PolymorphicDomainObjectContainer<Task>`
    Type Parameters:
      `T` - The task type
    Parameters:
      `name` - The name of the task.
      `type` - The task type.
      `configurationAction` - The action to run to configure the task. This action runs when the task is required.
    Returns:
      A `Provider` whose value will be the task, when queried.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    Since:
      4.9

  - ### register

    <T extends Task> TaskProvider<T> register(String name, Class<T> type) throws InvalidUserDataException
    Defines a new task, which will be created when it is required. A task is 'required' when the task is located using query methods such as `TaskCollection.getByName(java.lang.String)`, when the task is added to the task graph for execution or when `Provider.get()` is called on the return value of this method.

    It is generally more efficient to use this method instead of `create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `create(java.lang.String, java.lang.Class)`, as those methods will eagerly create and configure the task, regardless of whether that task is required for the current build or not. This method, on the other hand, will defer creation until required.

    Specified by:
      `register` in interface `PolymorphicDomainObjectContainer<Task>`
    Type Parameters:
      `T` - The task type
    Parameters:
      `name` - The name of the task.
      `type` - The task type.
    Returns:
      A `Provider` whose value will be the task, when queried.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    Since:
      4.9

  - ### register

    <T extends Task> TaskProvider<T> register(String name, Class<T> type, Object... constructorArgs) throws InvalidUserDataException
    Defines a new task, which will be created when it is required passing the given arguments to the `@Inject`-annotated constructor. A task is 'required' when the task is located using query methods such as `TaskCollection.getByName(java.lang.String)`, when the task is added to the task graph for execution or when `Provider.get()` is called on the return value of this method. All values passed to the task constructor must be non-null; otherwise a `NullPointerException` will be thrown

    It is generally more efficient to use this method instead of `create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `create(java.lang.String, java.lang.Class)`, as those methods will eagerly create and configure the task, regardless of whether that task is required for the current build or not. This method, on the other hand, will defer creation until required.

    Type Parameters:
      `T` - The task type
    Parameters:
      `name` - The name of the task.
      `type` - The task type.
      `constructorArgs` - The arguments to pass to the task constructor
    Returns:
      A `Provider` whose value will be the task, when queried.
    Throws:
      `NullPointerException` - If any of the values in `constructorArgs` is null.
      `InvalidUserDataException`
    Since:
      4.9

  - ### register

    TaskProvider<Task> register(String name) throws InvalidUserDataException
    Defines a new task, which will be created when it is required. A task is 'required' when the task is located using query methods such as `TaskCollection.getByName(java.lang.String)`, when the task is added to the task graph for execution or when `Provider.get()` is called on the return value of this method.

    It is generally more efficient to use this method instead of `create(java.lang.String)`, as that method will eagerly create the task, regardless of whether that task is required for the current build or not. This method, on the other hand, will defer creation until required.

    Specified by:
      `register` in interface `NamedDomainObjectContainer<Task>`
    Parameters:
      `name` - The name of the task.
    Returns:
      A `Provider` whose value will be the task, when queried.
    Throws:
      `InvalidUserDataException` - If a task with the given name already exists in this project.
    Since:
      4.9

  - ### replace

    Task replace(String name)

    Creates a `Task` with the given name and adds it to this container, replacing any existing task with the same name.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Parameters:
      `name` - The name of the task to be created
    Returns:
      The newly created task object
    See Also:
      - `More information about how tasks are exposed by name in build scripts`

  - ### replace

    <T extends Task> T replace(String name, Class<T> type)

    Creates a `Task` with the given name and type, and adds it to this container, replacing any existing task of the same name.

    After the task is added, it is made available as a property of the project, so that you can reference the task by name in your build file.

    Parameters:
      `name` - The name of the task to be created.
      `type` - The type of task to create.
    Returns:
      The newly created task object
    See Also:
      - `More information about how tasks are exposed by name in build scripts`