Skip to content

/commands/gradle/gradle-wrapper-upgrade

gradle wrapper --gradle-version: upgrade the Gradle wrapper

The commands on this page have not been executed by our verification runner yet.updated
tool
Gradle
versions
Gradle 7.x, Gradle 8.x, Gradle 9.x
os
any

./gradlew wrapper --gradle-version 8.14.3 upgrades the project's Gradle wrapper: it writes the new version into gradle/wrapper/gradle-wrapper.properties. Run ./gradlew wrapper (or any task) a second time so the new Gradle version also regenerates gradlew, gradlew.bat and gradle-wrapper.jar with its own scripts, then commit all four files. Everybody who runs ./gradlew afterwards gets the new version.

Upgrade

bash
./gradlew --version                                   # current wrapper version
./gradlew wrapper --gradle-version 8.14.3             # pin a version
./gradlew wrapper --gradle-version latest             # newest stable release
./gradlew wrapper                                     # second run: new scripts and JAR
./gradlew --version                                   # confirm
git add gradlew gradlew.bat gradle/wrapper/

Pass the exact version you want. Optional flags add a checksum and choose the distribution type:

bash
./gradlew wrapper --gradle-version 8.14.3 --distribution-type all
./gradlew wrapper --gradle-version 8.14.3 --gradle-distribution-sha256-sum SHA256

The properties file

gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionSha256Sum=SHA256

Editing distributionUrl by hand also changes the version, but running the wrapper task keeps the scripts and JAR in step and validates the arguments.

Options of the wrapper task

OptionWhat it does
--gradle-version 8.14.3Gradle version to use; also latest, release-candidate, nightly, or 9 / 9.1 for the newest matching release
--distribution-type bin|allbin (default) has only the runtime; all adds sources and docs for IDEs
--gradle-distribution-url URLDownload Gradle from a mirror or internal server
--gradle-distribution-sha256-sum SUMCheck the downloaded distribution against a checksum
--network-timeout MSDownload timeout in milliseconds
--no-validate-urlSkip checking that the distribution URL exists

Pitfalls

  • JDK compatibility. Every Gradle version supports a range of Java versions. Running a new JDK with an old Gradle fails with Unsupported class file major version; upgrading the wrapper is the usual fix. Check the compatibility matrix in the Gradle documentation before choosing a version.
  • Deprecations become errors. Major upgrades remove APIs that the previous version only deprecated. Run ./gradlew build --warning-mode all on the old version first to see what will break.
  • Plugins. Old versions of the Android Gradle Plugin, Kotlin or Spring Boot plugins may not support the new Gradle. Upgrade them in the same change.
  • Missing JAR. If gradle-wrapper.jar is not committed (or is in .gitignore), CI fails with Could not find or load main class GradleWrapperMain.

How to confirm it worked

./gradlew --version prints the new Gradle version together with the JVM it runs on. git diff gradle/wrapper/gradle-wrapper.properties shows the new distributionUrl, and a clean ./gradlew build on CI confirms that the plugins work with it. See the Gradle wrapper for how the scripts find and download the distribution.

FAQ

Do I need Gradle installed to upgrade the wrapper?

No. Run the wrapper task through the existing wrapper: ./gradlew wrapper --gradle-version X. The old version runs the task and writes the new version into gradle-wrapper.properties.

Which files must be committed after the upgrade?

gradlew, gradlew.bat, gradle/wrapper/gradle-wrapper.jar and gradle/wrapper/gradle-wrapper.properties. Without the JAR, the wrapper fails with Could not find or load main class org.gradle.wrapper.GradleWrapperMain.

How do I find the latest Gradle version?

Use --gradle-version latest (or release-candidate, release-nightly, nightly) with the wrapper task, or check the Gradle releases page. Read the upgrade notes before jumping a major version.

Sources