IntelliJ IDEA 2017.1 Help

Working with Gradle Projects

IntelliJ IDEA lets you manage Gradle projects. You can open, link, and synchronize changes of your Gradle project with IntelliJ IDEA project.

Opening an external Gradle project

  1. On the main menu, select File | Open.
    Alternatively, on the Welcome screen, click Open.
  2. In the dialog that opens, select a build.gradle file that you want to open or a directory that contains the build.gradle file and click OK.
  3. In the Open Project dialog, click Open as Project.
  4. In the Import from Gradle dialog, specify configuration options for your Gradle project and click OK.

IntelliJ IDEA imports the Gradle project and enables the Gradle Projects tool window.

Linking a Gradle project to IntelliJ IDEA project

When a project is created by importing from Gradle model, this link is established automatically and the Gradle Projects 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 import your Gradle project and enable the Gradle Projects tool window.
If the Gradle Projects tool window is active then you have at least one Gradle project linked.

  1. Open Gradle Projects tool window.
  2. In the Gradle Projects tool window, click /help/img/idea/2017.1/new.png to attach a gradle project.
  3. In the dialog that opens, select the desired build.gradle file, and click OK.
  4. 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 Projects tool window shows the toolbar and a tree view of Gradle entities.

Alternatively, you can link your Gradle project if you import your project as a Gradle module from the existing sources. In this case, you can link your Gradle project even if the Gradle Projects tool window is not available.

Navigating to the build.gradle file

  1. In the Gradle Projects tool window, right-click on the linked project.
  2. From the context menu select /help/img/idea/2017.1/icon_gradle.png.

    IntelliJ IDEA navigates to the appropriate Gradle configuration file and the related build.gradle file opens in the editor.

Detaching or ignoring a linked Gradle project

  1. In the Gradle Projects tool window, right-click on the linked project.
  2. From the context menu, select /help/img/idea/2017.1/delete.png (Delete ). Alternatively, you can select the linked project and click /help/img/idea/2017.1/delete.png on the Gradle tool bar.
  3. In the Import Gradle Projects pop-up window, clear the check box against the modules if you don't want to delete the project from the IntelliJ IDEA project's view.
  4. Click OK.

    The Gradle project is detached from the IntelliJ IDEA project and is not synchronized any more.

You can also de-activate Gradle project using Ignore Gradle Project option.

  1. In the Gradle Projects tool window, right-click the project that you want to ignore.
  2. In the context menu, select Ignore Gradle Project.
  3. In the window that opens, select projects and modules that you want to de-activate and click OK.

    In this case IntelliJ IDEA removes the selected projects and modules from the IntelliJ IDEA project's view and will not import them any more. However, you still are able to see the list of ignored Gradle modules and projects in the Gradle Projects tool window.

    If you want to activate your Gradle projects or modules, select Unignore Gradle Projects from the context menu.

Refreshing a linked Gradle project

  1. In the Gradle tool window, right-click on the linked project.
  2. From the context menu, select /help/img/idea/2017.1/refresh.png.

    On pressing this button, IntelliJ IDEA parses the project structure in the Gradle Projects tool window.

    Note that if you configure a dependency through the Project Structure dialog, the dependency will only appear in the IntelliJ IDEA Project tool window, not in the Gradle tool window. Also, note that the next time you refresh your project, IntelliJ IDEA will remove the added dependency since IntelliJ IDEA considers the Gradle configuration as a single source of truth.

Configuring Gradle Composite Build

Before you start configuring your composite build, make sure you have the Gradle version 3.1 or higher configured for your project.

Also, note that there are some restrictions on using Gradle composite build .

You can use settings.gradle file to include Gradle builds for your Gradle composite build.

  1. Open the settings.gradle file in the editor.
  2. Using includeBuild command, specify the location of the builds you want to add as dependencies to you project.

You can also use the Gradle Projects tool window to configure your composite build.

  1. Open your Gradle project.
  2. Link other Gradle projects that you want to use for your composite build.
  3. In the Gradle Projects tool window, right-click your main project and from the context menu select Composite Build Configuration.
  4. In the Gradle Project Build Composite dialog, select projects that you want to include in your Gradle composite build.
  5. Refresh your main Gradle project.

    IntelliJ IDEA finds the included Gradle projects and treats them as IntelliJ IDEA modules.

See Also

Last modified: 5 April 2017