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 version Gradle versions
15 Not yet supported
14 6.3 - 6.5
13 6.0 - 6.2.2
11 5.0 - 5.6.4
10 4.7 - 4.10.3
9 4.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?.

Watch this video demonstrating the ideas from this article.

Stop reading Gradle articles like these

This article helps you fix a specific problem, but it doesn't teach you the Gradle fundamentals you need to really help your team succeed.

Instead, follow a step-by-step process that makes getting started with Gradle easy.

Download this Free Quick-Start Guide to building simple Java projects with Gradle.

  • Learn to create and build Java projects in Gradle.
  • Understand the Gradle fundamentals.