Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD

## org.gradle.api
[Java] Interface Task

    public interface Task
    extends java.lang.Comparable

A `Task` represents a single atomic piece of work for a build, such as compiling classes or generating javadoc.

Each task belongs to a Project. You can use the various methods on TaskContainer to create and lookup task instances. For example, TaskContainer.add creates an empty task with the given name. You can also use the `task` keyword in your build file:

     task myTask
     task myTask { configure closure }
     task myType << { task action }
     task myTask(type: SomeType)
     task myTask(type: SomeType) { configure closure }

Each task has a name, which can be used to refer to the task within its owning project, and a fully qualified path, which is unique across all tasks in all projects. The path is the concatenation of the owning project's path and the task's name. Path elements are separated using the {

value:
  org.gradle.api.Project#PATH_SEPARATOR} character.

  ### Task Actions

  A `Task` is made up of a sequence of Action objects. When the task is executed, each of the actions is executed in turn, by calling Action#execute#execute. You can add actions to a task by calling doFirst(Action) or doLast(Action).

  Groovy closures can also be used to provide a task action. When the action is executed, the closure is called with the task as parameter. You can add action closures to a task by calling doFirst(groovy.lang.Closure) or doLast(groovy.lang.Closure) or using the left-shift << operator.

  There are 2 special exceptions which a task action can throw to abort execution and continue without failing the build. A task action can abort execution of the action and continue to the next action of the task by throwing a StopActionException. A task action can abort execution of the task and continue to the next task by throwing a StopExecutionException. Using these exceptions allows you to have precondition actions which skip execution of the task, or part of the task, if not true.

  ### Dependencies

  A task may have dependencies on other tasks. Gradle ensures that tasks are executed in dependency order, so that the dependencies of a task are executed before the task is executed. You can add dependencies to a task using dependsOn(Object...) or setDependsOn(Iterable). You can add objects of any of the following types as a dependency:

  - A `String` task path or name. A relative path is interpreted relative to the task's Project. This allows you to refer to tasks in other projects.
  - A Task.
  - A closure. The closure may take a `Task` as parameter. It may return any of the types listed here. Its return value is recursively converted to tasks. A `null` return value is treated as an empty collection.
  - A TaskDependency object.
  - A Buildable object.
  - A `Collection`, `Map` or an array. May contain any of the types listed here. The elements of the collection/map/array are recursively converted to tasks.
  - A `Callable`. The `call()` method may return any of the types listed here. Its return value is recursively converted to tasks. A `null` return value is treated as an empty collection.
  - An `Object`. The object's `toString()` method is interpreted as a task path or name.

  ### Using a Task in a Build File

  #### Dynamic Properties

  A `Task` has 3 'scopes' for properties. You can access these properties by name from the build file or by calling the property(String) method.

  - The `Task` object itself. This includes any property getters and setters declared by the `Task` implementation class. The properties of this scope are readable or writable based on the presence of the corresponding getter and setter methods.
  - The additional properties of the task. Each task object maintains a map of additional properties. These are arbitrary name -> value pairs which you can use to dynamically add properties to a task object. The properties of this scope are readable and writable.
  - The convention properties added to the task by each Plugin applied to the project. A Plugin can add properties and methods to a task through the task's Convention object. The properties of this scope may be readable or writable, depending on the convention objects.

  #### Dynamic Methods

  A Plugin may add methods to a `Task` using its Convention object.

Authors:
  Hans Dockter

Field Summary
`static java.lang.String` | `TASK_ACTION`
`static java.lang.String` | `TASK_DEPENDS_ON`
`static java.lang.String` | `TASK_DESCRIPTION`
`static java.lang.String` | `TASK_NAME`
`static java.lang.String` | `TASK_OVERWRITE`
`static java.lang.String` | `TASK_TYPE`

Method Summary

Methods inherited from interface java.lang.Comparable
java.lang.Comparable#compareTo(java.lang.Object)

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Field Detail

### TASK_ACTION

    public static final java.lang.String TASK_ACTION

### TASK_DEPENDS_ON

    public static final java.lang.String TASK_DEPENDS_ON

### TASK_DESCRIPTION

    public static final java.lang.String TASK_DESCRIPTION

### TASK_NAME

    public static final java.lang.String TASK_NAME

### TASK_OVERWRITE

    public static final java.lang.String TASK_OVERWRITE

### TASK_TYPE

    public static final java.lang.String TASK_TYPE

Groovy Documentation