Gradle Task Execution Overview

Gradle Task Execution Overview

Key Points on Gradle Task Execution

1. Not All Tasks Run by Default

2. How Tasks Get Executed

✅ Explicit Invocation

./gradlew myCustomTask

This manually runs myCustomTask if it exists.

🔄 Task Dependencies

Tasks can be linked via dependsOn, causing them to execute automatically:

task myTask {
    dependsOn 'compileJava'
}

Now, running ./gradlew myTask also runs compileJava.

⚙️ Gradle Lifecycle Tasks

Certain high-level tasks trigger multiple others:

./gradlew build

This runs:

3. Why Some Tasks Never Run

4. How to Check What Will Run

To see what tasks will execute without actually running them:

./gradlew <task-name> --dry-run

Example:

./gradlew build --dry-run

This simulates execution and prints the task sequence.


TL;DR