/glossary/gradle/gradle-wrapper
What is the Gradle Wrapper (gradlew)?
- tool
- Gradle
- versions
- Gradle 7.x – 9.x
- os
- linux, macos, windows
The Gradle Wrapper is a small set of files committed with a project (gradlew, gradlew.bat and gradle/wrapper/) that runs the build with a specific Gradle version. The first time you run ./gradlew build, it downloads that version into ~/.gradle/wrapper/dists/ and then uses it; later runs reuse the download. Nobody needs Gradle installed, and every developer and CI job builds with the same version.
The files
| File | Purpose |
|---|---|
| gradlew | Shell script for Linux and macOS |
| gradlew.bat | Batch script for Windows |
| gradle/wrapper/gradle-wrapper.jar | Small program that downloads and starts the right Gradle distribution |
| gradle/wrapper/gradle-wrapper.properties | Which Gradle version to use (distributionUrl) and where to store it |
Commit all four. The version lives in distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-X.Y-bin.zip(X.Y stands for the Gradle version of the project.)
Use it
./gradlew build # Linux, macOS (Git Bash too)
gradlew.bat build # Windows cmd / PowerShell: .\gradlew.bat build
./gradlew --version # Gradle version the wrapper usesIf ./gradlew fails with Permission denied on Linux or macOS, the execute bit was lost (common after a checkout from Windows): run chmod +x gradlew and commit it with git update-index --chmod=+x gradlew.
Upgrade the Gradle version
./gradlew wrapper --gradle-version X.Y # rewrites the properties file and scripts
./gradlew wrapper # run again so the new version updates the wrapper JAR tooRun it twice as shown: the first run uses the old Gradle to write the new version; the second runs with the new version and refreshes the wrapper files themselves. Commit the changed files.