How to properly update the Gradle wrapper
The Gradle wrapper is a self-contained Gradle runner and distribution that's typically built into your Gradle project. It's bundled into the project is to guarantee that all developers working on the project have a similar build environment. This means that updating the Gradle wrapper is effectively bumping up the Gradle version for the entire team.
Simply, you should almost always favor using it instead of an installed Gradle distribution.
A typical radle project is organized with the wrapper *.jar
in the gradle
folder in the project.
.
├── build.gradle
├── settings.gradle
|
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
|
├── gradlew
└── gradlew.bat
Inspecting your gradle-wrapper.properties
file should tell you the current version used in your project.
...
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
A lot of users simply bump up the version number here and call it a day. However, this is a poor way of performing the update because it doesn't update the generated gradlew
and gradlew.bat
execution scripts.
Instead, you should use the wrapper to update itself by running,
./gradlew wrapper --gradle-version 4.6 --distribution-type bin
Simply pass in the new version as well as the distribution type, either all
which includes sources and documentation or bin
which only ships with the binaries.
As a bonus tip, it's generally a good idea to also include the sha256 checksum of the new version in your gradle-wrapper.properties
file for added security[1].
gradle.org (2018). The Gradle Wrapper - Gradle User Manual. [online] Docs.gradle.org. Available at: https://docs.gradle.org/current/userguide/gradle_wrapper.html [Accessed 15 Apr. 2018]. ↩︎