IntelliJ IDEA 2019.1 Help

Gradle

Create a new Gradle project

  1. Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click Create New Project on the welcome screen: Otherwise, select File | New | Project from the main menu.

  2. Select Gradle from the options on the left.

  3. Specify the project SDK and an additional framework or a library (IntelliJ IDEA adds the appropriate plugin to the build.gradle file). Click Next.

  4. 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.

    If a parent Gradle project is specified, the specified fields can be inherited (click Inherit) from the parent.
    Click Next.
  5. On the next page of the wizard, configure Auto-import, source-sets, and a Gradle version for your project.

    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.

    Click Next.

  6. 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.

  1. 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 wrapper task 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.

  2. 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.

  1. In a project, on the main menu, select File| New | Module to open the New Module wizard.

  2. 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 moduleFolder to select a different name if you have other linked Gradle projects.

Import a project from a Gradle model

  1. Launch the New Project wizard. If no project is currently opened in IntelliJ IDEA, click Import Project on the welcome screen. Otherwise, select File | New | Project from Existing Sources 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.

  2. 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.

  3. 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.)

  4. 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.

  5. Click Finish.

Import a Gradle module

  1. You can start your module's import in one of the following ways:
    • From the main menu, select File | New | Module from Existing Sources.

    • In the Project Structure dialog, on the Module page, click icons general add icon and select Import Module.

    • In the Gradle projects tool window, on the toolbar, click gradle data to import icon icon.

  2. In the dialog that opens, select a module you want to import and click OK.

  3. If necessary, perform the steps described in the Importing a Gradle project section and click Finish.

  4. 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.

Last modified: 5 June 2019

See Also

Language and Framework-Specific Guidelines:

External Links: