Java, Maven and Gradle 25 cheatsheet

Java, Maven and Gradle 25: Gradle

13 common Java, Maven and Gradle 25 tasks.

Create a Gradle project

Generate a new project interactively.

gradle init

Add the Gradle wrapper

Generate gradlew so everyone builds with the same Gradle version.

gradle wrapper

Build the project

Compile, test and package.

./gradlew build

Clean and build

Delete the build folder, then build.

./gradlew clean build

Run the tests with Gradle

Compile and run the unit tests.

./gradlew test

Run one test class

Run the tests in a single class.

./gradlew test --tests "com.example.UserServiceTest"

Build with Gradle without running tests

Exclude the test task from the build.

./gradlew build -x test

List available tasks

Show the tasks you can run.

./gradlew tasks

Show the Gradle dependency tree

Print the dependencies of the project.

./gradlew dependencies

Find why a dependency is included

Show how a dependency is resolved and which dependency brings it in.

./gradlew dependencyInsight --dependency guava

Refresh dependencies

Ignore cached dependency resolution and check the repositories again.

./gradlew build --refresh-dependencies

Rebuild on file changes

Re-run the task whenever its inputs change.

./gradlew test --continuous

Show a full stack trace

Print the stack trace of build failures to diagnose them.

./gradlew build --stacktrace

Was this page helpful?