api / org.gradle.api.tasks / TaskContainer

TaskContainer

interface TaskContainer : TaskCollection<Task>, PolymorphicDomainObjectContainer<Task>

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

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

Functions

create

abstract fun create(options: MutableMap<String, *>): Task

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:

OptionDescriptionDefault Value {@value org.gradle.api.Task#TASK_NAME}The name of the task to create.None. Must be specified. {@value org.gradle.api.Task#TASK_TYPE}The class of the task to create.org.gradle.api.DefaultTask {@value org.gradle.api.Task#TASK_ACTION}The closure or Action to execute when the task executes. See Task#doFirst(Action).null {@value org.gradle.api.Task#TASK_OVERWRITE}Replace an existing task?false {@value org.gradle.api.Task#TASK_DEPENDS_ON}The dependencies of the task. See here for more details.[] {@value org.gradle.api.Task#TASK_GROUP}The group of the task.null {@value org.gradle.api.Task#TASK_DESCRIPTION}The description of the task. null {@value org.gradle.api.Task#TASK_CONSTRUCTOR_ARGS}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 {@value org.gradle.api.Task#TASK_OVERWRITE} option is not set to true, an exception is thrown.

abstract fun create(options: MutableMap<String, *>, configureClosure: Closure<Any>): Task

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. See here for more details.

abstract fun create(name: String, configureClosure: Closure<Any>): Task

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.

abstract fun create(name: String): Task

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.

abstract fun <T : Task> create(name: String, type: Class<T>): T

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.

abstract fun <T : Task> create(name: String, type: Class<T>, vararg constructorArgs: Any): T

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.

abstract fun <T : Task> create(name: String, type: Class<T>, configuration: Action<in T>): T

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.

findByPath

abstract fun findByPath(path: String): Task

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.

getByPath

abstract fun getByPath(path: String): Task

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.

register

abstract fun register(name: String, configurationAction: Action<in Task>): TaskProvider<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 #getByName(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(String, Action) or #create(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.

abstract fun <T : Task> register(name: String, type: Class<T>, configurationAction: Action<in T>): TaskProvider<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 #getByName(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(String, Class, Action) or #create(String, 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.

abstract fun <T : Task> register(name: String, type: Class<T>): TaskProvider<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 #getByName(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(String, Class, Action) or #create(String, 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.

abstract fun <T : Task> register(name: String, type: Class<T>, vararg constructorArgs: Any): TaskProvider<T>

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 #getByName(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(String, Class, Action) or #create(String, 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.

abstract fun register(name: String): 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 #getByName(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(String), as that methods will eagerly create he 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.

replace

abstract fun replace(name: String): Task

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.

abstract fun <T : Task> replace(name: String, type: Class<T>): T

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. See here for more details.

Inherited Functions

containerWithType

abstract fun <U : T> containerWithType(type: Class<U>): NamedDomainObjectContainer<U>

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

getAt

abstract fun getAt(name: String): T

{@inheritDoc}

getByName

abstract fun getByName(name: String, configureClosure: Closure<Any>): T
abstract fun getByName(name: String): T

{@inheritDoc}

matching

abstract fun matching(spec: Spec<in T>): TaskCollection<T>
abstract fun matching(closure: Closure<Any>): TaskCollection<T>

{@inheritDoc}

maybeCreate

abstract fun <U : T> maybeCreate(name: String, type: Class<U>): U

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

named

abstract fun named(name: String): TaskProvider<T>

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

whenTaskAdded

abstract fun whenTaskAdded(action: Action<in T>): Action<in T>

Adds an Action to be executed when a task is added to this collection.

abstract fun whenTaskAdded(closure: Closure<Any>): Unit

Adds a closure to be called when a task is added to this collection. The task is passed to the closure as the parameter.

withType

abstract fun <S : T> withType(type: Class<S>): TaskCollection<S>

{@inheritDoc}

Extension Functions

create

fun <T : Task> TaskContainer.create(name: String, vararg arguments: Any): T

Creates a Task with the given name and type, passing the given arguments to the javax.inject.Inject-annotated constructor, and adds it to this project tasks container.