api / org.gradle.api / Project / task

task

abstract fun task(name: String): Task

Creates a Task with the given name and adds it to this project. Calling this method is equivalent to calling #task(java.util.Map, String) with an empty options map.

After the task is added to the project, 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 project, an exception is thrown.

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 task(args: MutableMap<String, *>, name: String): Task

Creates a Task with the given name and adds it to this project. 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_TYPE}The class of the task to create.org.gradle.api.DefaultTask {@value org.gradle.api.Task#TASK_OVERWRITE}Replace an existing task?false {@value org.gradle.api.Task#TASK_DEPENDS_ON}A task name or set of task names which this task depends on[] {@value org.gradle.api.Task#TASK_ACTION}A closure or Action to add to the task.null {@value org.gradle.api.Task#TASK_DESCRIPTION}A description of the task. null {@value org.gradle.api.Task#TASK_GROUP}A task group which this task belongs to. null

After the task is added to the project, 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 project and the override option is not set to true, an exception is thrown.

Parameters

args - The task creation options.

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 task(args: MutableMap<String, *>, name: String, configureClosure: Closure<Any>): Task

Creates a Task with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task. A map of creation options can be passed to this method to control how the task is created. See #task(java.util.Map, String) for the available options.

After the task is added to the project, 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 project and the override option is not set to true, an exception is thrown.

Parameters

args - The task creation options.

name - The name of the task to be created

configureClosure - The closure to use to configure the created task.

Exceptions

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

Return
The newly created task object

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

Creates a Task with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task.

After the task is added to the project, 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 created task.

Exceptions

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

Return
The newly created task object