IntelliJ Gradle Support: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 34: Line 34:
{{External|https://www.jetbrains.com/help/idea/gradle-settings.html}}
{{External|https://www.jetbrains.com/help/idea/gradle-settings.html}}
====Gradle user home====
====Gradle user home====
This fields specified the location of stored Gradle caches, downloaded files, etc. If Gradle location has been defined by the environment variables <code>GRADLE_HOME</code> or <path>PATH</path>, IntelliJ deduces this location, and suggests this path as the default value. If not, the path must be specified manually.
This fields specified the location of stored Gradle caches, downloaded files, etc. If Gradle location has been defined by the environment variables <code>GRADLE_HOME</code> or <code>PATH</code>, IntelliJ deduces this location, and suggests this path as the default value. If not, the path must be specified manually.
 
====Generate *.iml files for modules imported from Gradle====
====Generate *.iml files for modules imported from Gradle====
Usually disabled.
Usually disabled.

Revision as of 21:43, 30 June 2021

External

Internal

Overview

Gradle is supported by IntelliJ via two plugins, which are installed and enabled by default: "Gradle" and "Gradle Extension". Gradle integration allows creating a Gradle project from the IDE, or opening an existing Gradle project with the IDE and managing it.

Concepts

Gradle Projects and IntelliJ Projects

Multiple Gradle projects can exists inside an IntelliJ Project, but the usual setup is to have one IntelliJ Project per Gradle project. The relationship between an IntelliJ Project and a Gradle project is established when the Gradle project is opened from the IDE, by opening the directory containing the Gradle project (build.gradle or settings.gradle). Also see Link a Gradle Project to an IntelliJ Project below.

Gradle JVM

https://www.jetbrains.com/help/idea/gradle.html#gradle_jvm

IDE determines the Gradle JVM according to the following algorithm, evaluating in order:

Language Level

The language level settings are applied for a source root or for a module. For a module, the module language level is set to sourceCompatibility in the build.gradle file. If a IDE Gradle project has a single linked Gradle project then the project default language level is set to the minimum language level among the module language levels. The preview part is set to the conjunction of preview flags of the module source sets. The source set module language level is set to the corresponding combination of sourceCompatibility property and --enable-preview flag.

Gradle Version

The version of Gradle to be used for a project can be configured in Gradle Settings by selecting one of the following sources:

JVM Options for Gradle

https://www.jetbrains.com/help/idea/gradle.html#gradle_vm_options

JVM options can be added to the Gradle project by specifying them in the gradle.properties file.

Gradle Settings

https://www.jetbrains.com/help/idea/gradle-settings.html

Gradle user home

This fields specified the location of stored Gradle caches, downloaded files, etc. If Gradle location has been defined by the environment variables GRADLE_HOME or PATH, IntelliJ deduces this location, and suggests this path as the default value. If not, the path must be specified manually.

Generate *.iml files for modules imported from Gradle

Usually disabled.

Gradle projects

Download external annotations for dependencies
Build and run

If "IntelliJ IDEA" is used to build, it'll do an incremental build.

Gradle JVM

See Gradle JVM above.

Use Gradle from

See Gradle Version above.

Operations

Create a New Gradle Project from the IDE

https://www.jetbrains.com/help/idea/gradle.html#project_create_gradle

Open an Existing Gradle Project

https://www.jetbrains.com/help/idea/gradle.html#gradle_import_project_start

Link a Gradle Project to an IntelliJ Project

https://www.jetbrains.com/help/idea/gradle.html#link_gradle_project

Add a New Gradle Module to an Existing Gradle Project

https://www.jetbrains.com/help/idea/gradle.html#gradle_add_module

Gradle Home

If asked to specify Gradle home, and get "Gradle location is incorrect", use the "libexec" subdirectory (/usr/local/Cellar/gradle/4.9/libexec).

IDEA Gradle Plugin

IDEA Plugin

Configuring Gradle Sources

TODO: Gradle Operations | IDE Configuration

Importing a Project form a Gradle Model

Use auto-import - If selected, re-import of the project is done automatically every time you make changes to the project.

Group modules. See Grouping Modules.

SNAPSHOT Refresh Problem

There are cases when Gradle pulls the latest version of the SNAPSHOT and caches it in its dependency cache, but IntelliJ IDEA Gradle plugin does not seem to notice it and uses an old version of the snapshot. This is troublesome during debugging, when the source code as displayed by IntelliJ does not match the bytecode being debugged.

Possible solutions for this (have not tested any of them, do that next time when I need it):

1. Refresh Dependencies of the Gradle Module

Gradle tab -> Select the module -> Right click -> Refresh Dependencies

2. Remove the Problem Dependency

Project Tab -> External Libraries -> expand Gradle: library-name -> Select "library root" -> Delete.

Then go to the Gradle tab and refresh dependencies.