Every Gradle project is driven from gradlew; knowing the basic commands is table stakes for JVM and Android work.
Gradle projects ship a wrapper: the scripts gradlew (Unix) and gradlew.bat plus gradle/wrapper/gradle-wrapper.properties, which pins the exact Gradle version. Running ./gradlew downloads that version on first use, so every developer and CI machine builds with the same Gradle. Always use the wrapper rather than a globally installed gradle; update it with ./gradlew wrapper --gradle-version 9.1.
Common commands:
./gradlew buildcompiles, runs tests and assembles artifacts../gradlew test,./gradlew run(with theapplicationplugin),./gradlew clean../gradlew taskslists available tasks;./gradlew help --task testexplains one../gradlew projectsand./gradlew dependenciesinspect the build.
Useful flags: -q quiet, --info / --debug for more output, --stacktrace on failures, --offline to use only the local cache, -x test to skip a task, --continue to run as much as possible after a failure, and -p dir to build another directory.
Gradle keeps a daemon process running between builds to stay fast; ./gradlew --stop stops it. Settings for the daemon, parallelism and the JVM live in gradle.properties.
Task names can be abbreviated by camel-case initials: ./gradlew cT runs compileTestJava if unambiguous.
Example
# Pin and fetch the project's Gradle version (committed to git)
cat gradle/wrapper/gradle-wrapper.properties | grep distributionUrl
# distributionUrl=https\://services.gradle.org/distributions/gradle-9.1-bin.zip
./gradlew build # compile + test + assemble
./gradlew test --tests "com.acme.*" # run a subset of tests
./gradlew build -x test # skip the test task
./gradlew run --args="--port 8080" # application plugin
./gradlew tasks --all # every task, including internal ones
./gradlew dependencies --configuration runtimeClasspath
./gradlew clean build --offline --stacktrace
./gradlew wrapper --gradle-version 9.1 # upgrade the wrapper
./gradlew --stop # stop the background daemonRemember
- Use ./gradlew, never a global gradle, so versions match everywhere
- build = compile + test + assemble; -x skips a task
- tasks, dependencies and help --task inspect the build
- A daemon keeps builds fast between runs
Watch out for
- Committing a project without the wrapper files, so teammates build with different Gradle versions.