Build Tools
Updated for 2026

Gradle Build Tool Commands & Groovy/Kotlin Cheatsheet 2026

Essential handbook for Gradle builds, command-line arguments, task execution, dependency management, daemon administration, and cache refreshing.

Task Execution

./gradlew tasks
List all available tasks configured in the active Gradle build project.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew tasks

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew compileJava
Compile all Java source code files in the project.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew compileJava

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew test
Execute all unit tests and generate interactive HTML reports.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew test

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew build
Run a full build, compiling code, running tests, and generating the production artifacts.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew build

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew clean
Delete the 'build' directory containing compiled classes and artifacts.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew clean

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date

Dependency & Report

./gradlew dependencies
List the dependency tree of the active project to trace transitive libraries.

When to Use

When inspecting dependencies, debugging transitive updates, or finding where a library version collision occurs.

Common Mistakes

Assuming dependencies are uniform. Be careful to check specific configurations like implementation, testImplementation, or runtimeOnly.

Shortcut / Pro-Tip

Use 'dependencyInsight' to track the precise resolution path of a single library.

Example

./gradlew dependencies

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew dependencyInsight --dependency <name>
Generate precise detail about how a specific dependency is resolved.

When to Use

When inspecting dependencies, debugging transitive updates, or finding where a library version collision occurs.

Common Mistakes

Assuming dependencies are uniform. Be careful to check specific configurations like implementation, testImplementation, or runtimeOnly.

Shortcut / Pro-Tip

Use 'dependencyInsight' to track the precise resolution path of a single library.

Example

./gradlew dependencyInsight --dependency <name>

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date

Caching & Updates

./gradlew build --refresh-dependencies
Force Gradle to download fresh copies of remote dependencies, ignoring caches.

When to Use

When inspecting dependencies, debugging transitive updates, or finding where a library version collision occurs.

Common Mistakes

Assuming dependencies are uniform. Be careful to check specific configurations like implementation, testImplementation, or runtimeOnly.

Shortcut / Pro-Tip

Use 'dependencyInsight' to track the precise resolution path of a single library.

Example

./gradlew build --refresh-dependencies

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew build --offline
Execute builds using only locally cached libraries, without checking remote connections.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew build --offline

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date

Daemon Admin

./gradlew --status
Query the state and list of active, running background Gradle daemons.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew --status

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date
./gradlew --stop
Terminate and shut down all active background Gradle daemons to free up RAM.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

./gradlew --stop

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date

Wrapper Utilities

gradle wrapper --gradle-version <version>
Generate or update the Gradle wrapper script with a specific Gradle engine version.

When to Use

When designing highly parallelized, incremental, and custom build pipelines in modern Java, Kotlin, or Android projects.

Common Mistakes

Invoking the global system-installed gradle binary directly instead of the self-contained project wrapper script (./gradlew).

Shortcut / Pro-Tip

Run build tasks with '--parallel' and enable Gradle build caching to experience blazing-fast compile loop speeds.

Example

gradle wrapper --gradle-version <version>

Output Example

Console / Terminal
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-date

Gradle Best Practices

1Always Use the Gradle Wrapper

Commit gradlew, gradlew.bat, and the gradle-wrapper files to version control, making builds instantly bootable and uniform.

2Expose Private Dependencies with 'implementation'

Use 'implementation' instead of 'api' by default to minimize compile classpath leaking, drastically speeding up compilation.

3Utilize Configuration Avoidance

Use modern Gradle task configuration APIs (like tasks.register) instead of tasks.create to skip configuring tasks that aren't being executed.

4Structure Builds inside buildSrc

Move custom build plugins, task classes, and shared dependency version definitions into the 'buildSrc' directory to keep build scripts clean and readable.

5Define Clear Task Dependencies

Never run tasks out-of-order. Establish explicit task execution bounds using 'dependsOn' or 'mustRunAfter' directives.

Common Gradle Errors & Solutions

Error

Configuration on demand is not supported

Solution

An outdated plugin violates configuration phase assumptions. Solution: Turn off configuration on demand or update the plugin.

Error

Could not find method implementation() for arguments

Solution

The dependency block was declared in a scope where the Java plugin was not applied. Solution: Ensure 'plugins { id 'java' }' is placed at the top.

Error

Out of Memory Exception (JVM heap error)

Solution

The Gradle daemon process has exhausted its allocated memory. Solution: Increase heap space inside your project's gradle.properties file (e.g. org.gradle.jvmargs=-Xmx2048m).

Error

Task path is ambiguous

Solution

The specified task name matches multiple sub-project tasks. Solution: Run the task specifying the precise sub-project prefix (e.g., :app:build).

Error

Gradle Daemon became unresponsive / was killed

Solution

The daemon process crashed due to system RAM limits. Solution: Run with '--no-daemon' in constrained environments like CI servers.

Common Gradle Interview Questions

Q1What is Gradle and what are its key features?

Gradle is a modern, high-performance build automation tool that supports multiple languages (Java, Kotlin, C++, etc.). It combines the power of Ant and Maven but uses Groovy or Kotlin DSL scripts instead of XML, and supports highly optimized incremental builds.

Q2What is the Gradle Wrapper and why is it recommended?

The Gradle Wrapper is a script (gradlew or gradlew.bat) and supporting files that download and use a designated Gradle version. It ensures that everyone building the project uses the identical, verified Gradle version, avoiding environment discrepancies.

Q3How does Gradle achieve faster build speeds than Maven?

Gradle utilizes incremental builds (only rebuilds out-of-date tasks), build caching (reuses outputs from previous builds/machines), compiler daemon processes, and parallel task execution.

Q4What are the differences between implementation and api dependency configurations?

'implementation' keeps dependencies private to the module, meaning they do not leak onto the compile classpath of dependent modules. 'api' exposes dependencies transitively, forcing consumer modules to recompile if they change.

Q5What is a Gradle Task?

A Task is a single atomic piece of work that a build performs, such as compiling classes, running unit tests, or uploading artifacts.