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
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 tasksOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 compileJavaOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 testOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 buildOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 cleanOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateDependency & Report
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 dependenciesOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateCaching & Updates
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-dependenciesOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 --offlineOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateDaemon Admin
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 --statusOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWhen 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 --stopOutput Example
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateWrapper Utilities
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
BUILD SUCCESSFUL in 3s
8 actionable tasks: 3 executed, 5 up-to-dateGradle 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
Configuration on demand is not supported
An outdated plugin violates configuration phase assumptions. Solution: Turn off configuration on demand or update the plugin.
Could not find method implementation() for arguments
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.
Out of Memory Exception (JVM heap error)
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).
Task path is ambiguous
The specified task name matches multiple sub-project tasks. Solution: Run the task specifying the precise sub-project prefix (e.g., :app:build).
Gradle Daemon became unresponsive / was killed
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.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com