Creating 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.gradlefile). Click Next. - On the next page of the wizard, specify 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.gradlefile.- GroupId -
groupIdof the new project. You can omit this field if you plan to deploy your project locally. - ArtifactId -
artifactIdthat is added as a name of your new project. - Version -
versionof the new project. By default, this field is specified automatically.
Click Next. - GroupId -
-
On the next page of the wizard, configure Auto-import, source roots
(so the default directory structure with main and test sub directories can be created), source-sets
, and
a Gradle version for your project.
Click Next. - Specify the name and location settings. Click Finish.
Configuring a gradle version for a gradle project
IntelliJ IDEA lets you use different options to configure a Gradle version when you create or import your Gradle project. You can use a default Gradle wrapper, use the Gradle wrapper as a task, or configure a local Gradle distribution.
- On the Gradle settings page either when you create or import a Gradle project,
or select
in the Gradle projects tool window, 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 the precise Gradle version.
The Gradle version is saved in gradle-wrapper.propertiesfile in the Gradle directory of your project. We recommend to 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 withgradle-wrapper.propertiesfile for some reason or you want to control which Gradle version you want your project to use. However, note that if you initially used a 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 need to run the wrapper task, so thegradle-wrapper.propertiesfile updates as well.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.propertiesfile will be updated and might have inconsistencies if you use this type of the wrapper configuration. - Use Gradle local distribution - select this option if you want 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.
- Use default gradle wrapper (recommended) - select this option to use
Gradle wrapper
- Press OK (in the wizard, press Next).
Adding a new gradle module to an existing project
You can add a Gradle module to the project in which you are already working.
- In a project, on the main menu, select to open 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 the 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 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.
Importing 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
build.gradlefile or a directory containingbuild.gradlefile. 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 the 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 check box 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 required dependencies are not present in the dependencies' cache, a 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.
Importing 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 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 modules or data you want to include in your project and click OK.