# Interface TaskExecutionGraph

@ServiceScope({org.gradle.internal.service.scopes.Scope.Build.class,org.gradle.internal.service.scopes.Scope.Project.class}) public interface TaskExecutionGraph

A `TaskExecutionGraph` is responsible for managing the execution of the `Task` instances which are part of the build. The `TaskExecutionGraph` maintains an execution plan of tasks to be executed (or which have been executed), and you can query this plan from your build file.

You can access the `TaskExecutionGraph` by calling `Gradle.getTaskGraph()`. In your build file you can use `gradle.taskGraph` to access it.

The `TaskExecutionGraph` is populated only after all the projects in the build have been evaluated. It is empty before then. You can receive a notification when the graph is populated, using `whenReady(groovy.lang.Closure)` or `addTaskExecutionGraphListener(TaskExecutionGraphListener)`.

Since:
  0.7

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addTaskExecutionGraphListener(TaskExecutionGraphListener listener)`
  Adds a listener to this graph, to be notified when this graph is ready.
  `void`
  `addTaskExecutionListener(TaskExecutionListener listener)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `void`
  `afterTask(Closure closure)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `void`
  `afterTask(Action<Task> action)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `void`
  `beforeTask(Closure closure)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `void`
  `beforeTask(Action<Task> action)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `List<Task>`
  `getAllTasks()`
  Returns the tasks which are included in the execution plan.
  `Set<Task>`
  `getDependencies(Task task)`
  Returns the dependencies of a task which are part of the execution graph.
  `boolean`
  `hasTask(String path)`
  Determines whether the given task is included in the execution plan.
  `boolean`
  `hasTask(Task task)`
  Determines whether the given task is included in the execution plan.
  `void`
  `removeTaskExecutionGraphListener(TaskExecutionGraphListener listener)`
  Remove a listener from this graph.
  `void`
  `removeTaskExecutionListener(TaskExecutionListener listener)`
  Deprecated.
  This method is not supported when configuration caching is enabled.
  `void`
  `whenReady(Closure closure)`
  Adds a closure to be called when this graph has been populated.
  `void`
  `whenReady(Action<TaskExecutionGraph> action)`
  Adds an action to be called when this graph has been populated.

- ## Method Details

  - ### addTaskExecutionGraphListener

    void addTaskExecutionGraphListener(TaskExecutionGraphListener listener)

    Adds a listener to this graph, to be notified when this graph is ready.

    Parameters:
      `listener` - The listener to add. Does nothing if this listener has already been added.
    Since:
      0.7

  - ### removeTaskExecutionGraphListener

    void removeTaskExecutionGraphListener(TaskExecutionGraphListener listener)

    Remove a listener from this graph.

    Parameters:
      `listener` - The listener to remove. Does nothing if this listener was never added to this graph.
    Since:
      0.7

  - ### addTaskExecutionListener

    @Deprecated void addTaskExecutionListener(TaskExecutionListener listener)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Adds a listener to this graph, to be notified as tasks are executed.

    Parameters:
      `listener` - The listener to add. Does nothing if this listener has already been added.
    Since:
      0.7

  - ### removeTaskExecutionListener

    @Deprecated void removeTaskExecutionListener(TaskExecutionListener listener)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Remove a listener from this graph.

    Parameters:
      `listener` - The listener to remove. Does nothing if this listener was never added to this graph.
    Since:
      0.7

  - ### whenReady

    void whenReady(Closure closure)

    Adds a closure to be called when this graph has been populated. This graph is passed to the closure as a parameter.

    When the configuration cache is enabled, this callback only fires during the configuration phase (a cache miss). On a cache hit, the task graph is loaded from the cache and this callback is not invoked.

    Parameters:
      `closure` - The closure to execute when this graph has been populated.
    Since:
      0.7

  - ### whenReady

    void whenReady(Action<TaskExecutionGraph> action)

    Adds an action to be called when this graph has been populated. This graph is passed to the action as a parameter.

    When the configuration cache is enabled, this callback only fires during the configuration phase (a cache miss). On a cache hit, the task graph is loaded from the cache and this callback is not invoked.

    Parameters:
      `action` - The action to execute when this graph has been populated.
    Since:
      3.1

  - ### beforeTask

    @Deprecated void beforeTask(Closure closure)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Adds a closure to be called immediately before a task is executed. The task is passed to the closure as a parameter.

    Parameters:
      `closure` - The closure to execute when a task is about to be executed.
    Since:
      0.7

  - ### beforeTask

    @Deprecated void beforeTask(Action<Task> action)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Adds an action to be called immediately before a task is executed. The task is passed to the action as a parameter.

    Parameters:
      `action` - The action to execute when a task is about to be executed.
    Since:
      3.1

  - ### afterTask

    @Deprecated void afterTask(Closure closure)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Adds a closure to be called immediately after a task has executed. The task is passed to the closure as the first parameter. A `TaskState` is passed as the second parameter. Both parameters are optional.

    Parameters:
      `closure` - The closure to execute when a task has been executed
    Since:
      0.7

  - ### afterTask

    @Deprecated void afterTask(Action<Task> action)
    Deprecated.
    This method is not supported when configuration caching is enabled.

    Adds an action to be called immediately after a task has executed. The task is passed to the action as the first parameter.

    Parameters:
      `action` - The action to execute when a task has been executed
    Since:
      3.1

  - ### hasTask

    boolean hasTask(String path)

    Determines whether the given task is included in the execution plan.

    Parameters:
      `path` - the absolute path of the task.
    Returns:
      true if a task with the given path is included in the execution plan.
    Throws:
      `IllegalStateException` - When this graph has not been populated.
    Since:
      0.7

  - ### hasTask

    boolean hasTask(Task task)

    Determines whether the given task is included in the execution plan.

    Parameters:
      `task` - the task
    Returns:
      true if the given task is included in the execution plan.
    Throws:
      `IllegalStateException` - When this graph has not been populated.
    Since:
      0.7

  - ### getAllTasks

    List<Task> getAllTasks()

    Returns the tasks which are included in the execution plan. The order of the tasks in the result is compatible with the constraints (dependsOn/mustRunAfter/etc) set in the build configuration. However, Gradle may execute tasks in a slightly different order to speed up the overall execution while still respecting the constraints.

    Returns:
      The tasks. Returns an empty list if no tasks are to be executed.
    Since:
      0.7

  - ### getDependencies

    Set<Task> getDependencies(Task task)

    Returns the dependencies of a task which are part of the execution graph.

    Returns:
      The tasks. Returns an empty set if there are no dependent tasks.
    Throws:
      `IllegalStateException` - When this graph has not been populated or the task is not part of it.
    Since:
      4.6