All cheatsheetsJava Development

gradle

Gradle 8+

Quick reference for the Gradle CLI: project tasks, dependency management, multi-project builds, wrapper, configuration cache, and build scan — with common options and practical examples.

30 commands

Tasks

gradle tasks

List every task the current build defines, grouped by category. `--all` shows internal / hidden tasks too.

--all; --group=<group>; --quiet

gradle tasks --all
gradle help

Print help text for a specific task: description, group, declared inputs / outputs.

gradle help --task build
gradle :<module>:tasks

List tasks for a specific subproject in a multi-project build (replace `<module>` with the Gradle path).

gradle :web:tasks --all

Lifecycle

gradle build

Run the standard JVM build chain: `compile → processResources → classes → jar → test → check → assemble` (and a zip distribution if configured).

-x <task> exclude task; --parallel; --build-cache; --configuration-cache

gradle build -x test
gradle clean

Delete the build directory (`build/`) so the next build re-runs every task from scratch.

--no-rebuild don't auto-trigger the default lifecycle

gradle clean build
gradle assemble

Compile and package everything but skip the verification / test tasks. Faster feedback when you only need the jar.

gradle assemble
gradle check

Run all verification tasks (`test`, `lint`, etc.) without producing a jar. Use in CI as the pre-merge gate.

--continue keep going after a task failure

gradle check --continue
gradle test

Run unit tests (Test task). Use `--tests <pattern>` to narrow to specific classes / methods.

--tests com.acme.UserServiceTest; --tests '*User*'; --info

gradle test --tests 'com.acme.*ServiceTest'

Dependencies

gradle dependencies

Print the resolved dependency tree for a configuration (e.g. `compileClasspath`, `runtimeClasspath`, `testCompileClasspath`).

--configuration <name>; --all show every config

gradle dependencies --configuration runtimeClasspath | grep -i slf4j
gradle dependencyInsight --dependency <id>

Explain why a single dependency ended up at a specific version — useful for resolving version conflicts.

--dependency <group:artifact>; --configuration <name>

gradle dependencyInsight --dependency com.fasterxml.jackson.core:jackson-databind
gradle buildEnvironment

Print the resolved build-script classpath — every plugin / helper library the build itself uses.

gradle buildEnvironment
gradle refresh-dependencies

Force re-resolution of dynamic versions and snapshot dependencies.

--refresh-keys

gradle build --refresh-dependencies

Multi-project

gradle projects

List every project in the reactor (root + subprojects) with their project paths and descriptions.

gradle projects
gradle :<module>:<task>

Run a task in one subproject by Gradle path (`:` separator).

-p <dir> start from a subdir

gradle :order-service:test :web:assemble
gradle <task> --parallel

Execute independent tasks in parallel — useful for multi-module builds with independent test suites.

--max-workers=<N>; --no-parallel

gradle test --parallel --max-workers=4

Performance

gradle --build-cache <task>

Enable the local build cache (task outputs reused across branches / branches). Combine with a remote cache in `settings.gradle` for CI.

--no-build-cache

gradle assemble --build-cache
gradle --configuration-cache <task>

Gradle 8.x — cache the configuration phase for sub-millisecond startup of large multi-project builds.

--no-configuration-cache

gradle test --configuration-cache
gradle --no-daemon <task>

Disable the Gradle daemon — useful for low-memory CI or for diagnosing daemon-only bugs.

gradle --no-daemon test
gradle --stop

Stop all running Gradle daemons. Pair with a clean rebuild if cached state is suspect.

gradle --stop && gradle clean build

Diagnose

gradle --scan <task>

Run a task then publish a build scan (link printed at end). Requires accepting the Build Scan terms once.

--scan -Dscan.tag.<name>=<value>

gradle assemble --scan
gradle --info <task>

Enable INFO logging — task start / finish, up-to-date checks, dependency resolutions.

--debug / -d even more detail

gradle test --info | tee gradle-info.log
gradle --stacktrace <task>

Print full stack traces on any failure.

--warning-mode=all show every deprecation warning

gradle build --stacktrace

Wrapper

./gradlew <task>

Run a task through the Gradle Wrapper — uses the Gradle version pinned in `gradle/wrapper/gradle-wrapper.properties`.

./gradlew clean build
gradle wrapper --gradle-version <v>

Generate / refresh the wrapper files with a specific Gradle distribution.

--distribution-type bin | all; --gradle-distribution-url <url>

gradle wrapper --gradle-version 8.7 --distribution-type bin

Publish

gradle publish

Upload artifacts to the repository declared under `publishing` in `build.gradle`. Common targets: Maven Central via Sonatype, private Nexus / Artifactory.

-Drelease.useAutomaticVersion=true; -PpublishTo=staging

gradle publishToMavenLocal
gradle publishToMavenLocal

Install the build into the local Maven repository (`~/.m2/repository`) so a neighboring Maven build can depend on it.

gradle publishToMavenLocal

Misc

gradle --version

Print Gradle / JVM / OS info, including the daemon status.

gradle --version
gradle properties

List every project property (ext.*, gradle.*, system) — useful when chasing overridden values.

gradle properties | grep version
gradle init

Bootstrap a new Gradle project: choose DSL (Groovy / Kotlin), pick a project type, optionally wire a Git remote.

--type basic; --type java-application; --type java-library; --dsl groovy|kotlin

gradle init --type java-library --dsl kotlin
gradle :<module>:tasks --group <name>

Filter the task list to a single task group (e.g. `build`, `verification`, `documentation`, `help`).

gradle tasks --group verification

Related command cheatsheets

About Gradle

Gradle is a JVM-based build tool first released in 2008 (by Hans Dockter and the Gradleware / Gradle Inc team). It was created to combine the expressiveness of Apache Ant with the dependency management of Apache Ivy, all wrapped in a Groovy-based DSL that is now also available in Kotlin (Kotlin DSL, `.kts`). Gradle powers Android builds (Android Studio uses Gradle by default), Spring Boot starters, Kotlin Multiplatform, and many large JVM monorepos. The current stable line is Gradle 8.x (8.7+). Gradle excels at incremental builds via task input/output fingerprinting, parallel task execution, the build cache (local + remote), and the configuration cache (8.x). Tasks are declared in `build.gradle` / `build.gradle.kts` and grouped into chains via `dependsOn`; plugins add new tasks (`java`, `java-library`, `application`, `org.springframework.boot`, `com.android.application`). Gradle never uploads source code — only the artifacts declared by publishing plugins. The wrapper (`gradlew`) bundles a small launcher that downloads the Gradle distribution pinned in `gradle-wrapper.properties`, guaranteeing every developer and CI agent uses the same Gradle version.

Cheatsheet version 1.0.0