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.
Create a new Gradle project
Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click Create New Project on the welcome screen. Otherwise, select from the main menu.
Select Gradle from the options on the left.
- Specify the project SDK and an additional framework or a library (IntelliJ IDEA adds the appropriate plugin to the build.gradle file). Click Next.
- On the next page of the wizard, specify the fields which resemble Maven naming conventions. 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.
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.
Click Next. Specify the name and location settings. Click Finish.
Open an existing Gradle project
If no project is currently opened in IntelliJ IDEA, click Open on the welcome screen. Otherwise, select from the main menu.
In the dialog that opens, select a file that contains a Gradle project description build.gradle. Click OK.
In the dialog that opens, click Open as Project. IntelliJ IDEA opens and syncs the project in the IDE.
If you need to adjust the Gradle settings options, refer to Gradle settings.
Link a Gradle project to the 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 and a new Gradle module to an existing project
You can add a Gradle module to a project in which you are already working.
In a project, from the main menu, select New Module wizard.
to open theIf 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.
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.
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 Use Gradle from list select one of the following options:
- 'gradle-wrapper.properties' file: 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 in Gradle build script: 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. Specified location: 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.
- 'gradle-wrapper.properties' file: this is a recommended default option that uses Gradle wrapper.
Add VM options for the Gradle project
You can specify VM options for your Gradle project using the gradle.properties file.
In the Project tool window, right-click the project and from the context menu, select .
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.