api / org.gradle.api.tasks / TaskContainer / register

register

@Incubating 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.

Parameters

name - The name of the task.

configurationAction - The action to run to configure the task. This action runs when the task is required.

Exceptions

InvalidUserDataException - If a task with the given name already exists in this project.

Return
A Provider that whose value will be the task, when queried.

Since
4.9

@Incubating 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.

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.

- The task type

Exceptions

InvalidUserDataException - If a task with the given name already exists in this project.

Return
A Provider that whose value will be the task, when queried.

Since
4.9

@Incubating 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.

Parameters

name - The name of the task.

type - The task type.

- The task type

Exceptions

InvalidUserDataException - If a task with the given name already exists in this project.

Return
A Provider that whose value will be the task, when queried.

Since
4.9

@Incubating 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.

Parameters

name - The name of the task.

type - The task type.

constructorArgs - The arguments to pass to the task constructor

- The task type

Exceptions

NullPointerException - If any of the values in constructorArgs is null.

Return
A Provider that whose value will be the task, when queried.

Since
4.9

@Incubating 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.

Parameters

name - The name of the task.

Exceptions

InvalidUserDataException - If a task with the given name already exists in this project.

Return
A Provider that whose value will be the task, when queried.

Since
4.9