# TaskContainer

API Documentation: | `TaskContainer`

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.

### Properties

No properties

### Methods

Method | Description
`containerWithType(type)` | Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.
`create(name)` | Creates a `Task` with the given name and adds it to this container.
`create(name, configureClosure)` | 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.
`create(name, type)` | Creates a `Task` with the given name and type, and adds it to this container.
`create(name, type, constructorArgs)` | 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
`create(name, type, configuration)` | Creates a `Task` with the given name and type, configures it with the given action, and adds it to this container.
`create(name, configureAction)` | Creates a new item with the given name, adding it to this container, then configuring it with the given action.
`create(options)` | 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:
`create(options, configureClosure)` | 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 `TaskContainer.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.
`findByPath(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.
`getByName(name)` | Locates an object by name, failing if there is no such object.
`getByName(name, configureClosure)` | Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.
`getByName(name, configureAction)` | Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.
`getByPath(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 throws an exception if no task with the given path exists.
`maybeCreate(name)` | Looks for an item with the given name, creating and adding it to this container if it does not exist.
`maybeCreate(name, type)` | Looks for an item with the given name and type, creating and adding it to this container if it does not exist.
`named(name)` | Locates a task by name, without triggering its creation or configuration, failing if there is no such object.
`named(name, type)` | Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
`named(name, type, configurationAction)` | Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
`named(name, configurationAction)` | Locates a object by name, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
`named(nameFilter)` | Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection. This method will NOT cause any pending objects in this container to be realized.
`register(name)` | 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.
`register(name, type)` | 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.
`register(name, type, constructorArgs)` | 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
`register(name, type, configurationAction)` | 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.
`register(name, configurationAction)` | 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.
`replace(name)` | Creates a `Task` with the given name and adds it to this container, replacing any existing task with the same name.
`replace(name, type)` | Creates a `Task` with the given name and type, and adds it to this container, replacing any existing task of the same name.

### Script blocks

No script blocks

### Method details

#### ``NamedDomainObjectContainer`<`U`>` `containerWithType`(``Class`<`U`>` type)

Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.

#### `Task` `create`(`String` name)

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.

#### `Task` `create`(`String` name, `Closure` configureClosure)

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.

#### `T` `create`(`String` name, ``Class`<`T`>` type)

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.

#### `T` `create`(`String` name, ``Class`<`T`>` type, ``Object`...` constructorArgs)

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.

#### `T` `create`(`String` name, ``Class`<`T`>` type, ``Action`<? super `T`>` configuration)

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.

#### `T` `create`(`String` name, ``Action`<? super `T`>` configureAction)

Creates a new item with the given name, adding it to this container, then configuring it with the given action.

#### `Task` `create`(``Map`<`String`, ?>` options)

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:

<caption>Permitted map keys</caption>
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(org.gradle.api.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.

#### `Task` `create`(``Map`<`String`, ?>` options, `Closure` configureClosure)

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 `TaskContainer.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.

#### `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.

#### `T` `getByName`(`String` name)

Locates an object by name, failing if there is no such object.

#### `T` `getByName`(`String` name, `Closure` configureClosure)

Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.

#### `T` `getByName`(`String` name, ``Action`<? super `T`>` configureAction)

Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.

#### `Task` `getByPath`(`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 throws an exception if no task with the given path exists.

#### `T` `maybeCreate`(`String` name)

Looks for an item with the given name, creating and adding it to this container if it does not exist.

#### `U` `maybeCreate`(`String` name, ``Class`<`U`>` type)

Looks for an item with the given name and type, creating and adding it to this container if it does not exist.

#### ``TaskProvider`<`T`>` `named`(`String` name)

Locates a task by name, without triggering its creation or configuration, failing if there is no such object.

#### ``TaskProvider`<`S`>` `named`(`String` name, ``Class`<`S`>` type)

Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.

#### ``TaskProvider`<`S`>` `named`(`String` name, ``Class`<`S`>` type, ``Action`<? super `S`>` configurationAction)

Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.

#### ``TaskProvider`<`T`>` `named`(`String` name, ``Action`<? super `T`>` configurationAction)

Locates a object by name, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.

#### ``TaskCollection`<`T`>` `named`(``Spec`<`String`>` nameFilter)

Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection. This method will NOT cause any pending objects in this container to be realized.

#### ``TaskProvider`<`Task`>` `register`(`String` name)

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 `TaskContainer.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.

#### ``TaskProvider`<`T`>` `register`(`String` name, ``Class`<`T`>` type)

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 `TaskContainer.create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `TaskContainer.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.

#### ``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. 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 `TaskContainer.create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `TaskContainer.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.

#### ``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. 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 `TaskContainer.create(java.lang.String, java.lang.Class, org.gradle.api.Action)` or `TaskContainer.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.

#### ``TaskProvider`<`Task`>` `register`(`String` name, ``Action`<? super `Task`>` configurationAction)

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 `TaskContainer.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.

#### `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.

#### `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.