gradle
8.5

# task

abstract fun task(name: String): Task(source)

Creates a Task with the given name and adds it to this project. Calling this method is equivalent to calling task 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.

#### Return

The newly created task object

#### Parameters

name

The name of the task to be created

#### Throws

InvalidUserDataException

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

abstract fun task(args: Map<String, out Any>, name: String): Task(source)

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:

`{@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.

#### Return

The newly created task object

#### Parameters

args

The task creation options.

name

The name of the task to be created

#### Throws

InvalidUserDataException

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

abstract fun task(args: Map<String, out Any>, name: String, configureClosure: Closure): Task(source)

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

#### Return

The newly created task object

#### 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.

#### Throws

InvalidUserDataException

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

abstract fun task(name: String, @DelegatesTo(value = Task::class) configureClosure: Closure): Task(source)

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

#### Return

The newly created task object

#### Parameters

name

The name of the task to be created

configureClosure

The closure to use to configure the created task.

#### Throws

InvalidUserDataException

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

abstract fun task(name: String, configureAction: Action<out Any>): Task(source)

Creates a Task with the given name and adds it to this project. Before the task is returned, the given action 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

#### Return

The newly created task object

#### Parameters

name

The name of the task to be created

configureAction

The action to use to configure the created task.

#### See also

tasks.TaskContainer

#### Throws

InvalidUserDataException

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