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.
groupIdof the new project. You can omit this field if you plan to deploy your project locally.
artifactIdthat is added as a name of your new project.
versionof the new project. By default, this field is specified automatically.
You can also specify how to group modules in your project. For example, if you want to sort out your modules and group them by their qualified names, use the using qualified names option. In this case when module groups are generated using Gradle
group, the prefixes in module names are also accounted for.
For more information, refer to the Grouping modules section.
Specify the name and location settings. Click Finish.
Configure a Gradle version for a project
IntelliJ IDEA lets you use different options to configure a Gradle version when you create or import your Gradle project. You can use the default Gradle wrapper, use a Gradle wrapper as a task, or configure a local Gradle distribution.
- On the Gradle settings page when you create or import a Gradle project, choose one of the following options:
Use default gradle wrapper (recommended): select this option to use Gradle wrapper. In this case you delegate the update of Gradle versions to Gradle and get an automatic Gradle download for the build. It 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. We recommend that you use this option to eliminate any Gradle version problems in your project.
- Use gradle task configuration: select this option to configure a Gradle wrapper according to the
wrappertask configuration. It might be convenient if you don't want to work with the gradle-wrapper.properties file for some reason or you want to control which Gradle version you want your project to use. Note that if you initially used the default Gradle wrapper option and then decided to use the Gradle wrapper task configuration when you change anything in the task such as changing the Gradle version, you don't need to run the wrapper task manually, since the gradle-wrapper.properties file update is done implicitly by IntelliJ IDEA during importing.
Also, note that if, for example, you use VCS in your project and each team member syncs the project via gradle, the gradle/wrapper/gradle-wrapper.properties file will be updated and might have inconsistencies if you use this type of wrapper configuration.
Use Gradle local distribution: 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.
Press OK (in the wizard, press Next).
Add 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, on the main menu, select New Module wizard.to open the
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.
Import a project from a Gradle model
- Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click Import Project on the welcome screen. Otherwise, select from the main menu.
Note that you can also select File | Open from the main menu and choose the build.gradle file or a directory containing the build.gradle file. IntelliJ IDEA will import a Gradle project even if the project was not opened or imported before.
In the dialog that opens, select the directory that contains the project you want to import or a file that contains a Gradle project description (build.gradle). Click OK.
- On the first page of the Import Project wizard, in Import Project from External model, select Gradle and click Next.
(This page is not displayed if IntelliJ IDEA has guessed what you are importing.)
- On the next page of the Import Project wizard, specify Gradle project settings that are the same as when you create a Gradle project.
Also, specify the following global Gradle settings:
Offline work: use this checkbox to work with Gradle in the offline mode. In this case Gradle will use dependencies from the cache. Gradle will not attempt to access the network to perform dependency resolution. If the required dependencies are not present in the cache, build execution will fail.
Service directory path: use this field to override the default Gradle home location directory.
Gradle VM options: use this field to specify VM options for your Gradle project.
Import a Gradle module
- You can start your module's import in one of the following ways:
From the main menu, select.
In the Project Structure dialog, on the Module page, click icon and select Import Module.
In the Gradle projects tool window, on the toolbar, click icon.
In the dialog that opens, select a module you want to import and click OK.
If necessary, perform the steps described in the Importing a Gradle project section and click Finish.
If you have a multi-module project the Select Project Data to Import dialog opens.
In the Select Project Data to Import dialog, select the modules or data you want to include in your project and click OK.