Gradle Wrapper
Introduction
The Gradle Wrapper is a small script (gradlew / gradlew.bat) plus metadata that downloads and runs a fixed Gradle version for the project. Teams commit Wrapper files so laptops and CI use the same Gradle without asking everyone to install globally. This chapter explains how it works and how to create or upgrade it.
Prerequisites
- First Gradle project
- JDK 21
Wrapper Files
gradlew # Unix/macOS shell script
gradlew.bat # Windows batch script
gradle/wrapper/
gradle-wrapper.jar # bootstrap downloader
gradle-wrapper.propertiesgradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/distsdistributionUrl pins the Gradle version. Change it when upgrading (or use the command below).
Why Teams Commit the Wrapper
| Without Wrapper | With Wrapper |
|---|---|
| “Install Gradle 8.12” in README | Clone repo, run ./gradlew |
| CI image must preinstall Gradle | CI only needs JDK |
| Version drift between developers | Same version everywhere |
Tip
Best Practice
Treat gradlew, gradlew.bat, and gradle/wrapper/* as source code. Never add them to .gitignore.
Create Wrapper in a New Project
If you built a project manually without Wrapper:
# From project root; requires global gradle once
gradle wrapper --gradle-version 8.12.1Verify:
./gradlew -versionUpgrade Wrapper Version
./gradlew wrapper --gradle-version 8.12.1Commit updated gradle-wrapper.properties (and jar if it changed). Teammates get the new version on next pull.
Run Builds Through Wrapper
./gradlew build
./gradlew test
./gradlew clean buildWindows:
gradlew.bat buildFirst run downloads Gradle into:
~/.gradle/wrapper/dists/Later runs reuse the cache.
CI and Servers
Pipeline step (Linux):
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- run: chmod +x gradlew
- run: ./gradlew buildNo apt install gradle required.
GRADLE_USER_HOME
Override cache location:
export GRADLE_USER_HOME=/data/gradle-cache
./gradlew buildUseful in CI with persisted volumes.
Offline and Air-Gapped (Brief)
- Build once online to populate
~/.gradle/wrapper/distsand dependency cache - Copy caches or use an internal mirror URL in
distributionUrland repository settings
Details vary by company infrastructure.
Wrapper vs Global gradle
| Command | Uses |
|---|---|
gradle build | Whatever gradle is on PATH |
./gradlew build | Version from gradle-wrapper.properties |
IDEA should use Wrapper for team projects (IntelliJ chapter).
Mini Example: Verify Team Alignment
./gradlew -versionEveryone should report the same Gradle line before opening a PR.
FAQ
Is gradle-wrapper.jar safe to commit?
Yes—it is the official bootstrap from Gradle releases.
Can I delete gradlew and use global Gradle only?
Possible but discouraged—CI and onboarding suffer.
Wrapper download slow or blocked?
Check proxy; set systemProp in gradle.properties or use internal mirror.