Groovy Documentation

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:

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.

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