- How do I upgrade Gradle?
- How to update Gradle
- What’s my current Gradle version?#
- Working on Windows?
- What updated Gradle version can I use?#
- How do I update my Gradle version?#
- How does the version update actually work?#
- Resources#
- Video
- Как мне обновить Gradle?
- 3 ответа
- Installation
- Prerequisites
- Additional resources
- Installing with a package manager
- › Additional helpful information
- Installing manually
- Step 1. Download the latest Gradle distribution
- Step 2. Unpack the distribution
- Step 3. Configure your system environment
- Step 4. Verify your installation
- › Additional helpful information
- Upgrade with the Gradle Wrapper
- › Additional helpful information
- Older Releases
- Command-Line Completion
How do I upgrade Gradle?
Advantages of sdkman: latest version supplied by gradle themselves.
I got error while running upgrade gradle as The following packages have unmet dependencies. powershell : Depends: liblttng-ust0 but it is not installed . I have to run this sudo apt-get -f install then sudo apt-get -f install gradle . This way, it deletes the previous one and installs the latest from scratch.
@AnumSheraz: powershell is in another repository altogether. It should not have anything to do with gradle. But it seems like sudo apt-get -f install fixed its problem.
you’re lifesaver. My gradle version was 2 and throws that exception: gradle failed to apply plugin id ‘com.google.protobuf’ After update gradle the problem is gone. Thanks.
This PPA does not serve up-to-date Gradle. Now my Gradle version is 5.2 (installed via apt ) while there’s 5.3.1 available for download from the official website.
You can also tell Gradle to update itself using a Gradle wrapper.
First you create the wrapper, then tell it to use the Gradle version of your choice:
gradle wrapper ./gradlew wrapper --gradle-version 4.9
Now this project will use Gradle 4.9, independent of what’s installed. However, you need to remember to run Gradle through the wrapper, i.e., run ./gradlew instead of plain gradle .
The wrapper allows you to have different projects using different Gradle versions easily.
When you commit the created wrapper to source control, everybody who checks out the project will use the same Gradle version. This can help a lot with incompatible build scripts, when something has changed between Gradle versions.
How to update Gradle
Get up to speed fast with my new book.
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
Working on Windows?
Just replace any time you see ./gradlew in this article with gradlew.bat e.g. gradlew.bat —version
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 :
$ ./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 . " to update what will be committed) (use "git checkout -- . " 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 , 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.
Video
Check out the accompanying video from the Tom Gregory Tech YouTube channel.
Как мне обновить Gradle?
Как мне перейти на Gradle 4.x? Желательно, с Umake, а не SDKMAN! что, кажется, то, что они предлагают.
(Я не хочу обновлять все пакеты из-за медленного соединения.)
3 ответа
Вы можете использовать ppa для почти всегда последней версии
sudo add-apt-repository ppa:cwchien/gradle sudo apt-get update sudo apt upgrade gradle
или SDKMAN для последней версии
curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install gradle
Преимущества sdkman: последняя версия поставляется самим Gradle.
Вы также можете указать Gradle обновить себя, используя оболочку Gradle.
Сначала вы создаете оболочку, а затем говорите ей использовать версию Gradle по вашему выбору:
gradle wrapper ./gradlew wrapper --gradle-version 4.9
Теперь этот проект будет использовать Gradle 4.9, независимо от того, что установлено. Тем не менее, вы должны помнить, чтобы запустить Gradle через обертку, то есть запустить ./gradlew вместо простого gradle ,
Оболочка позволяет легко создавать разные проекты, используя разные версии Gradle.
Когда вы отправляете созданную оболочку в систему управления версиями, все, кто проверяет проект, будут использовать одну и ту же версию Gradle. Это может очень помочь с несовместимыми сценариями сборки, когда что-то изменилось между версиями Gradle.
выберите бинарную ссылку согласно
v4.10.3
05 декабря 2018 г.
Загрузка: только двоичная или полная
после расширения загрузки просто обновите переменную PATH env var, чтобы получить этот новый двоичный файл
vi ~/.bashrc # or where ever your shell's env vars are defined
и добавьте следующую строку в конец ~/.bashrc
# replace ~/src/gradle-4.10.3/bin with your location export PATH=~/src/gradle-4.10.3/bin:$PATH
подтвердить эту работу, выдав
source ~/.bashrc gradle --version
Installation
The current Gradle release is 8.2.1. You can download binaries and view docs for all Gradle versions from the releases page.
Prerequisites
Gradle runs on all major operating systems and requires only a Java JDK version 8 or higher to be installed. To check, run java -version :
$ java -version java version "1.8.0_121"
Additional resources
- On-demand and live online training is available for free to Gradle users.
- Self-paced tutorials are a good place to try Gradle with a variety of languages in addition to the docs.
- Gradle has a visual build inspection tool: Build Scan™.
- Finally, the Gradle Newsletter is a great way to keep UP-TO-DATE , with issues crafted monthly.
Installing with a package manager
SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.
Homebrew is “the missing package manager for macOS”.
Other package managers are available, but the version of Gradle distributed by them is not controlled by Gradle, Inc. Linux package managers may distribute a modified version of Gradle that is incompatible or incomplete when compared to the official version (available from SDKMAN! or below).
› Additional helpful information
Installing manually
Step 1. Download the latest Gradle distribution
The current Gradle release is version 8.2.1, released on 10 Jul 2023. The distribution zip file comes in two flavors:
If in doubt, choose the binary-only version and browse docs and sources online.
Need to work with an older version? See the releases page.
Step 2. Unpack the distribution
Linux & MacOS users
Unzip the distribution zip file in the directory of your choosing, e.g.:
$ mkdir /opt/gradle $ unzip -d /opt/gradle gradle-8.2.1-bin.zip $ ls /opt/gradle/gradle-8.2.1 LICENSE NOTICE bin getting-started.html init.d lib media
Microsoft Windows users
Create a new directory C:\Gradle with File Explorer.
Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content. Drag the content folder gradle-8.2.1 to your newly created C:\Gradle folder.
Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.
Step 3. Configure your system environment
Linux & MacOS users
Configure your PATH environment variable to include the bin directory of the unzipped distribution, e.g.:
$ export PATH=$PATH:/opt/gradle/gradle-8.2.1/bin
Microsoft Windows users
In File Explorer right-click on the This PC (or Computer ) icon, then click Properties -> Advanced System Settings -> Environmental Variables .
Under System Variables select Path , then click Edit . Add an entry for C:\Gradle\gradle-8.2.1\bin . Click OK to save.
Step 4. Verify your installation
Open a console (or a Windows command prompt) and run gradle -v to run gradle and display the version, e.g.:
› Additional helpful information
Upgrade with the Gradle Wrapper
If your existing Gradle-based build uses the Gradle Wrapper, you can easily upgrade by running the wrapper task, specifying the desired Gradle version:
$ ./gradlew wrapper --gradle-version=8.2.1 --distribution-type=bin
Note that it is not necessary for Gradle to be installed to use the Gradle wrapper. The next invocation of gradlew or gradlew.bat will download and cache the specified version of Gradle.
$ ./gradlew tasks Downloading https://services.gradle.org/distributions/gradle-8.2.1-bin.zip .
› Additional helpful information
Older Releases
You can find all releases and their checksums on the releases page.
Command-Line Completion
Command-line completion scripts are available for bash and zsh. This provides completion for Gradle tasks and command-line options.