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

  1. On the Gradle settings page either when you create or import a Gradle project, or select images/settings.png 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.properties file 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 wrapper task configuration. It might be convenient if you don't want to work with gradle-wrapper.properties file 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 the gradle-wrapper.properties file 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.properties file 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.
  2. 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.

  1. In a project, on the main menu, select File| New | Module to open 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 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 images/moduleFolder.png to select a different name if you have other linked Gradle projects.

Importing 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 build.gradle file or a directory containing 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 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.)

  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 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.
    Click Finish.

Importing 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 images/add.png icon and select Import Module.
    • In the Gradle projects tool window, on the toolbar, click images/gradle_data_to_import_icon.png icon.
  2. In the dialog that opens, select a module you want to import and click OK.
  3. If necessary perform 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 modules or data you want to include in your project and click OK.

See Also

Language and Framework-Specific Guidelines:

External Links: