api / org.gradle.api.tasks / TaskContainer / create

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.

Parameters

options - The task creation options.

Exceptions

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

NullPointerException - If any of the values in {@value org.gradle.api.Task#TASK_CONSTRUCTOR_ARGS} is null.

Return
The newly created task object

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.

Parameters

options - The task creation options.

configureClosure - The closure to use to configure the task.

Exceptions

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

Return
The newly created task object

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

Overrides NamedDomainObjectContainer.create

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.

Parameters

name - The name of the task to be created

configureClosure - The closure to use to configure the task.

Exceptions

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

Return
The newly created task object

abstract fun create(name: String): Task

Overrides NamedDomainObjectContainer.create

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.

Parameters

name - The name of the task to be created

Exceptions

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

Return
The newly created task object

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

Overrides PolymorphicDomainObjectContainer.create

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.

Parameters

name - The name of the task to be created.

type - The type of task to create.

Exceptions

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

Return
The newly created task object

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

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

Exceptions

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

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

Return
The newly created task object

Since
4.7

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

Overrides PolymorphicDomainObjectContainer.create

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.

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.

Exceptions

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

Return
The newly created task object.