# Task Basics

version 9.1.0-branch-sigushkinDeclarativeComposabilitySpikeFromGh-20250805133820+0000

A task represents some independent unit of work that a build performs, such as compiling classes, creating a JAR, generating Javadoc, or publishing archives to a repository.

Tasks are the building blocks of every Gradle build.

Common types of tasks include:

- Compiling source code

- Running tests

- Packaging output (e.g., creating a JAR or APK)

- Generating documentation (e.g., Javadoc)

- Publishing build artifacts to repositories

Each task is independent but can depend on other tasks to run first. Gradle uses this information to figure out the most efficient order to execute tasks — skipping anything that’s already up to date.

## Running a task

To run a task, use the Gradle Wrapper from your project’s root directory. For example, to run the `build` task:

    $ ./gradlew build

This will run the `build` task and all of its dependencies.

## Listing available tasks

Gradle plugins and your build script define which tasks are available in a project. To see them:

    $ ./gradlew tasks

This shows a categorized list of tasks:

    Application tasks
    -----------------
    run - Runs this project as a JVM application

    Build tasks
    -----------
    assemble - Assembles the outputs of this project.
    build - Assembles and tests this project.

    ...

    Documentation tasks
    -------------------
    javadoc - Generates Javadoc API documentation for the main source code.

    ...

    Other tasks
    -----------
    compileJava - Compiles main Java source.

    ...

You can run any of these tasks directly using the `./gradlew <task-name>` command.

## Running tasks

If you have the `application` plugin applied in your build file, the `run` task should be available. You can run your project like this:

    $ ./gradlew run

Example output:

    > Task :app:compileJava
    > Task :app:processResources NO-SOURCE
    > Task :app:classes

    > Task :app:run
    Hello World!

    BUILD SUCCESSFUL in 904ms
    2 actionable tasks: 2 executed

Gradle ran all the tasks required to execute your application, including compiling it first. In this example, the output of the `run` task is a `Hello World` statement printed on the console.

## Task dependencies

Most tasks don’t run in isolation. Gradle knows which tasks depend on which others, and will automatically run them in the correct order.

For example, when you run `./gradlew build`, Gradle also runs tasks like `compileJava`, `test`, and `jar` first — because `build` depends on them:

    $ ./gradlew build

    > Task :app:compileJava
    > Task :app:processResources NO-SOURCE
    > Task :app:classes
    > Task :app:jar
    > Task :app:startScripts
    > Task :app:distTar
    > Task :app:distZip
    > Task :app:assemble
    > Task :app:check
    > Task :app:build

    BUILD SUCCESSFUL in 764ms
    7 actionable tasks: 7 executed

You don’t need to worry about ordering — Gradle figures it out for you.

To learn how to define your own tasks and control how they work, see the Task development chapter.

Next Step: Learn about Plugins >>