How to update Gradle

How to update Gradle

Using the Gradle wrapper means that a project can be fixed to a specific version of Gradle. If you want to update Gradle to a newer version though, follow the simple steps in this article.

What’s my current Gradle version?

Assuming your project is using the Gradle wrapper, which it most likely is, run ./gradlew --version:

$ ./gradlew --version

------------------------------------------------------------
Gradle 6.4.1
------------------------------------------------------------

Build time:   2020-05-15 19:43:40 UTC
Revision:     1a04183c502614b5c80e33d603074e0b4a2777c5

Kotlin:       1.3.71
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Windows 10 10.0 amd64

What updated Gradle version can I use?

You can go to the Gradle releases page to find the latest version.

If you’re using Java just remember that what Java version you want to build your project with influences what Gradle version you should choose:

Highest supported Java versionGradle versions
15Not yet supported
146.3 – 6.5
136.0 – 6.2.2
115.0 – 5.6.4
104.7 – 4.10.3
94.2.1 – 4.6

How do I update my Gradle version?

Just run ./gradlew wrapper --gradle-version <gradle-version>:

$ ./gradlew wrapper --gradle-version 6.5

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

You can double check this has worked by running ./gradlew --version again:

$ ./gradlew --version

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Windows 10 10.0 amd64

Commit all the changed files into version control. If you’re using git then the list should look like this when you run git status:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   gradle/wrapper/gradle-wrapper.jar
        modified:   gradle/wrapper/gradle-wrapper.properties
        modified:   gradlew
        modified:   gradlew.bat

That’s it! You’re all upgraded onto the new Gradle version. ✅

How does the version update actually work?

If you’re curious as to how that worked, read on.

Whenever you run anything using ./gradlew it executes a script in your project root directory. That script accesses a gradle-wrapper.properties file located in gradle/wrapper which contains the version of Gradle you’re targeting:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Gradle uses the distributionUrl property to download the new version of Gradle and stores it in your user home directory in ~/.gradle/wrapper/dists. The gradle-wrapper.jar file is used to do the actual download of the distribution.

When you update your Gradle version using ./gradlew wrapper --gradle-version <gradle-version>, all these files get changed automatically.

For even more details about how the Gradle wrapper works, check out the article What is the Gradle wrapper and why should you use it?.

Resources

✅ if you prefer to learn in video format, check out the accompanying video on the Tom Gregory Tech YouTube channel.

How to update Gradle

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top

Get the newsletter

Found this article helpful? Subscribe for monthly updates.

✅ All of my latest articles for the month
✅ Access to video tutorials
✅ Exclusive tips not found on my website