Как обновить gradle в intellij idea
In this last step, we’ll look at how to configure the Gradle Wrapper.
We saw how to tell IntelliJ IDEA where to get the settings of the Gradle Wrapper from. Projects generated using IntelliJ IDEA’s Gradle wizard will usually have a gradle-wrapper.properties file which contains the details of the version of Gradle to use for this project. Ideally we want this to use the latest version of Gradle, where possible, so that we get the most up to date support and features. The current version of Gradle at the time of writing is 7.0.2.

If you update the gradle-wrapper.properties file to have a different version number, IntelliJ IDEA will detect the changes and asks us to reload these changes. The IDE will download this new version of Gradle, and then rebuild the project using it.

The «.gradle» folder in your project has folders for all the versions of Gradle that you’ve used. We can safely delete the versions we’re not using any more if we want to reclaim some space.
In our last step we’ll summarise some of the shortcuts used and other tips.
Обновление версий
Своевременное обновление версий Gradle и его плагинов гарантирует, что вы используете наиболее актуальную версию без багов и уязвимостей.
Также с выходом новых обновлений появляются новые функции, которые, возможно, понадобятся в проекте.
Gradle
Мы используем Gradle Wrapper как обертку, которая автоматизирует процесс установки нужной версии Gradle.
Чтобы поменять версию Gradle в вашем проекте, необходимо перейти в директорию gradle/wrapper и открыть файл его настроек gradle-wrapper.properties :
# . # URL-адрес для загрузки дистрибутива Gradle distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip # .
Каталог с возможными версиями Gradle вы можете найти тут.
Gradle придерживается такого подхода к версионированию, при котором апдейты минорных версий не нарушают обратную совместимость. При обновлении же мажорных версий, например Gradle 6.9.1 ~> 7.0.2 , есть высокая вероятность, что что-то будет несовместимо, поэтому такие апдейты надо делать аккуратно и проверять, что будет с обеими платформами.
Plugins
Что делать если Android Studio предложила обновить Android Gradle Plugin (AGP) или Kotlin Gradle Plugin? Какие плагины и зависимости можно обновлять без последствий?
Kotlin и Android
В принципе, вы можете обновлять все плагины и зависимости, поддерживающие семантическое версионирование, но на минорных апдейтах, чтобы не нарушалась обратная совместимость.
С ноября 2020 года Android Gradle Plugin поддерживает семантическое версионирование, поэтому при обновлении AGP с версии 7.0 на версию 7.1 ничего сломаться не должно.
Kotlin поддерживает немного другой вид версионирования, о котором вы можете прочитать тут.
Например, если в вашем проекте используется Kotlin Multiplatform Plugin:
plugins kotlin("multiplatform") version "1.4.21" >
то при смене feature версии 1.4.21 ~> 1.5.21 нужно проверить компиляцию обеих платформ и работу кода во время выполнения. Также скорее всего придется обновлять и версии библиотек на те, которые поддерживают новую версию.
А при смене incremental ( 1.5.21 -> 1.5.30 ) и bugfix ( 1.5.20 -> 1.5.21 ) версий обратная совместимость сохраняется и проблем быть не должно.
Материалы
Gradle
IntelliJ IDEA supports a fully-functional integration with Gradle that helps you automate your building process. You can easily create a new Gradle project, open and sync an existing one, work with several linked projects simultaneously, and manage them.
You can also create a Gradle project and store it in the WSL environment or open it from the WSL file system. For more information, refer to the WSL section.
Create a new Gradle project
- Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click New Project on the welcome screen. Otherwise, select File | New | Project from the main menu.
- Name the new project and change its location if necessary.
- Select the Create Git repository to place the new project under version control. You will be able to do it later at any time. The .gitignore file is generated in any case.
- Select a language that you want to use in your project. Click if you want to add other languages available via plugins.
- Select Gradle in the list of Build system .
- Specify project’s SDK (JDK) or use the default one. If you don’t have a JDK on your machine, IntelliJ IDEA can quickly download the JDK for you. The Gradle project sync will wait until the JDK is downloaded.
- The selected Add sample code option will create a file with a basic code sample.
- Select Gradle DSL . You can select Groovy for traditional syntax or Kotlin as an alternative.
- In Advanced Settings , specify the fields which resemble the Maven coordinates. These settings might be helpful if you decide to deploy your project to a Maven repository. The fields you specify are added to the build.gradle file.
- Gradle distribution : select Gradle wrapper that is a default-preferable option or Local installation when you want to use the specific local Gradle version.
- Gradle version : if the wrapper option is selected, the latest Gradle distribution will be used unless you unselect the Auto-select option and select the specific version from the drop-down list. Alternatively, if the Local installation was selected then the version you defined locally is used.
- Auto-select : unselect this option to specify the Gradle version you want to use in your project.
- Use these settings for future projects : select this checkbox to use the configured Gradle version in your future projects.
- GroupId — groupId of the new project. You can omit this field if you plan to deploy your project locally.
- ArtifactId — artifactId that is added as a name of your new project.
- Version — version of the new project. By default, this field is specified automatically.
For more information about Maven coordinates, refer to Maven naming conventions.
Create a Java EE project with Gradle as a build tool
- Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click New Project on the welcome screen. Otherwise, select File | New | Project from the main menu.
- Under the Generators section, select Jakarta EE .
- Configure your project selecting the appropriate options such as your project’s name, location, language, and select Gradle as your build tool.
- Click Create . IntelliJ IDEA creates a Gradle project with the dedicated Gradle tool window and adds necessary dependencies. For the more detailed information, refer to Tutorial: Your first Java EE application.
Open an existing Gradle project
If you have the offline mode enabled in your project, the opening or re-importing of the project might fail. To fix the issue, disable the offline mode and re-import your project.
- If no project is currently opened in IntelliJ IDEA, click Open on the welcome screen. Otherwise, select File | Open from the main menu. If you have some custom plugins that require you to import your project from the IntelliJ IDEA model, press Control+Shift+A and search for the Project from Existing Sources action.
- In the dialog that opens, select a directory containing a Gradle project and click OK . IntelliJ IDEA opens and syncs the project in the IDE.
If you need to adjust the Gradle settings options, refer to Gradle settings.
Check Gradle JVM and language level
- Gradle JVM : when IntelliJ IDEA opens the Gradle project, it checks the gradle.properties file for the appropriate JVM version specified in org.gradle.java.home and uses it for the project. If it is not specified, then the project SDK is used. Alternatively, you can use the Gradle settings to configure the Gradle JVM.
- Language level : the language level settings are applied for a source root or for a module. If a Gradle project has a single linked project then the project default language level is set to the minimum language level among the module language levels. The module language level is set to sourceCompatibility in the build.gradle file. The preview part is set to the conjunction of preview flags of the module source sets. The source set module language level is set to the corresponding combination of sourceCompatibility property and —enable-preview flag.
Link a Gradle project to an IntelliJ IDEA project
You can have multiple Gradle projects inside one IntelliJ IDEA project. It might be helpful if you keep parts of code in different projects, have some legacy projects on which you need to work, have Gradle composite build or work with microservices. You can link such projects in IntelliJ IDEA and manage them simultaneously.
When you open a Gradle project, the link of the project is established automatically and the Gradle tool window is enabled.
If an IntelliJ IDEA project is not linked to a Gradle project, then the Gradle tool window is disabled. In this case, IntelliJ IDEA displays a message with a link that quickly lets you reimport your Gradle project and enable the Gradle tool window. If the Gradle tool window is active, then you have at least one Gradle project linked.
- Open the Gradle tool window.
- In the Gradle tool window, click to attach a Gradle project.
- In the dialog that opens, select the desired build.gradle file, and click OK .
- In the Import Module from Gradle window, specify options for the Gradle project that you are trying to link and click OK . The project is linked. The Gradle tool window shows the toolbar and a tree view of Gradle entities.
If you need to link back the previously unlinked project, in the Project tool window, right-click the added build.gradle or if it is a Gradle Kotlin module the build.gradle.kts file and select Import Gradle Project .
Add a new Gradle module to an existing Gradle project
You can add a Gradle module to a project in which you are already working.
- In the main menu, go to File| New | Module to open the New Module wizard .
- If the existing project is not the Gradle project then the process of adding a module is the same as Creating a new Gradle project. If the existing project is a Gradle project, then the process of adding a new module is shorter. You need to specify the name of your module in the ArtifactId field. The rest of the information is added automatically, and you can use either the default settings or change them according to your preferences. Also, note that Add as module to field, by default, displays the name of your project to which you are trying to add a module. You can click to select a different name if you have other linked Gradle projects.
Convert a regular project into a Gradle project
- Open your project in IntelliJ IDEA.
- In the Project tool window, right-click the name of your project and select New | File .
- In the dialog that opens enter build.gradle and click OK .
- Open the build.gradle file in the editor, add the information you need and re-open your project. The following minimal information should be included in the project’s build script file:
plugins < id 'java' >group ‘org.example’ version ‘1.0-SNAPSHOT’ repositories < mavenCentral() >sourceSets < main < java < srcDirs = ['src'] >> > dependencies < compile 'junit:junit:4.12' >
Access the Gradle settings
Use the Gradle settings to configure the build and run actions for each linked Gradle project, a Gradle version, importing of the project’s changes, and so on.

- In the Settings dialog ( Control+Alt+S ), go to Build, Execution, Deployment| Gradle . Click on the toolbar, in the Gradle tool window to access the Gradle settings.
- On the Gradle settings page, configure the available options and click OK to save the changes.
Configure a Gradle version for a project
IntelliJ IDEA lets you use different options to configure a Gradle version for your Gradle project. You can use the default Gradle wrapper, use a Gradle wrapper as a task, or configure a local Gradle distribution.

- Select in the Gradle tool window to quickly access the Gradle settings page.
- In the Distribution list select one of the following options:
- Wrapper : this is a recommended default option that uses Gradle wrapper. In this case you delegate the update of Gradle versions to Gradle and get an automatic Gradle download for the build. This option also lets you build with a precise Gradle version. The Gradle version is saved in the gradle-wrapper.properties file in the gradle directory of your project and helps you eliminate any Gradle version problems.
- Wrapper task : select this option to configure a Gradle wrapper according to the wrapper task configuration. It might be convenient if you prefer to control which Gradle version to use in the project. If you used the default Gradle wrapper option and then switched to the Gradle wrapper task configuration, changes you made in the task automatically update during the project import.
- Local installation : select this option if you want to manually download and use a specific Gradle version. Specify the location of your Gradle installation and JVM under which IntelliJ IDEA will run Gradle when you import the specified Gradle project and when you execute its tasks.
Click OK to save the changes.
Add VM options for the Gradle project
You can specify VM options for your Gradle project using the gradle.properties file.

- Create or open your Gradle project.
- In the Project tool window, right-click the project and from the context menu, select New | File .
- In the New File dialog, enter gradle.properties as a filename and click OK .
- Open the created file in the editor and add the VM options you need.
For more information, refer to the Gradle documentation.
Increase daemon heap size
You can adjust the existing Gradle daemon heap size for your project using the gradle.properties file.
- Create or open your Gradle project.
- In the Project tool window, right-click the project and from the context menu, select New | File .
- In the New File dialog, enter gradle.properties as a filename and click OK .
- Open the created file in the editor and specify the needed daemon size using the org.gradle.jvmargs=(JVM arguments) property. The default size is -Xmx512m «-XX:MaxMetaspaceSize=256m» . Check the following code snippet as a syntax example:
org.gradle.jvmargs=-Xmx4096m
For more information, refer to the Gradle documentation.
Как обновить версию Gradle
При использовании Gradle Wrapper версию Gradle можно обновить следующим образом.
Для начала проверим текущую версию для этого в Windows Power Shell выполняем:
.\gradlew —version
Build time: 2021-02-22 16:13:28 UTC
Revision: 9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78
Kotlin: 1.4.20
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 1.8.0_91 (Oracle Corporation 25.91-b15)
OS: Windows Server 2008 R2 6.1 amd64
Доступные релизы Gradle можно посмотреть по ссылке
https://gradle.org/releases/
Выполняем обновление
./gradlew wrapper —gradle-version 7.4.2
Второй способ обновить версию это изменить в файле gradle-wrapper.properties значение distributionUrl.
Пример :
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip
Этот способ также позволит вернуть версию Gradle обратно в случае когда новая версия не заработала.