Table of Contents
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.
Method | Description |
containerWithType(type) | Creates a regular container that wraps the polymorphic container presenting all elements of a specified type. |
create(name) | Creates a |
create(name, configureClosure) | Creates a |
create(name, type) | Creates a |
create(name, type, constructorArgs) | Incubating Creates a |
create(name, type, configuration) | Creates a |
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 |
create(options, configureClosure) | Creates a |
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. |
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 |
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 |
register(name, type, constructorArgs) | Defines a new task, which will be created when it is required passing the given arguments to the |
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 |
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 |
replace(name) | Creates a |
replace(name, type) | Creates a |
NamedDomainObjectContainer
<U
>
containerWithType
(Class
<U
>
type)
NamedDomainObjectContainer
<U
>Class
<U
>Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.
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. See here for more details.
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. See here for more details.
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. See here for more details.
Note: This method is incubating and may change in a future version of Gradle.
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. See here for more details.
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. See here for more details.
Creates a new item with the given name, adding it to this container, then configuring it with the given action.
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:
Option | Description | Default Value |
| The name of the task to create. | None. Must be specified. |
| The class of the task to create. | DefaultTask |
| The closure or Action to
execute when the task executes. See Task.doFirst(org.gradle.api.Action) . | null |
| Replace an existing task? | false |
| The dependencies of the task. See here for more details. | [] |
| The group of the task. | null
|
| The description of the task. |
null |
| 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. See here for more details.
If a task with the given name already exists in this container and the
option is not set to true, an exception is thrown.overwrite
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. See here for more details.
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.
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.
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.
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.
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)
TaskProvider
<T
>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)
TaskProvider
<S
>Class
<S
>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)
TaskProvider
<S
>Class
<S
>Action
<? super S
>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)
TaskProvider
<T
>Action
<? super T
>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.
TaskProvider
<Task
>
register
(String
name)
TaskProvider
<Task
>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)
TaskProvider
<T
>Class
<T
>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)
TaskProvider
<T
>Class
<T
>Object
...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)
TaskProvider
<T
>Class
<T
>Action
<? super T
>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)
TaskProvider
<Task
>Action
<? super Task
>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.
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. See here for more details.