Gradle in IntelliJ IDEA

IntelliJ IDEA reads a Gradle build and makes a project of it: the source folders become modules, the dependencies become libraries, and every task of the build appears in a tool window. This lesson lists the steps, because this container has no IDE and no screen to take a picture of.

Importing the project

  1. File → Open and pick the folder that holds settings.gradle, not a subfolder of it. IntelliJ recognises the build by that file.
  2. In the dialog, choose Open as Project, and let it use the wrapper: Use Gradle from: 'gradle-wrapper.properties' file is the default.
  3. Pick the JDK the build compiles with, 21 for this course, and wait for the first import. The status bar shows the Gradle sync, and the first one downloads the distribution and the dependencies.

An import that fails says why in the Build tool window: a plugin that cannot be resolved, a version the wrapper names and the network does not have, a JDK that is not installed. The message is the same one ./gradlew prints, which is why the command line stays the reference.

The Gradle tool window

View → Tool Windows → Gradle opens the window on the right. It holds the project tree with the tasks of every project under Tasks, and it is the same tree gradle tasks prints: build, documentation, help, verification. A double click runs a task; the run appears in the Run window with the same output as the terminal.

The window is a client of the daemon: it keeps one running for the project, which is why the first task of a session is slower than the second, and why a change to org.gradle.jvmargs needs Reload Gradle Project before it applies.

Running a task

  1. Open Gradle → shop → Tasks → build and double click build. The whole build runs, with its tests.
  2. Modify Run Configuration on a task adds arguments: --tests for a filtered test run, -Pshop.release=true for a property, --info for a log.
  3. Run Anything (Ctrl twice) takes a Gradle command directly: gradle :app:run --args="--fast" runs the same way the terminal would.

The settings that matter

Why there is no output here

Every other lesson of this course shows the output of the commands it names. This one cannot: the container has no IDE and no display, and the steps above are the steps of a program a reader runs on a desktop. Nothing in the lesson is a guess about a Gradle behaviour; the tasks, the flags and the settings are the ones this course uses from the command line, where every one of them is proved.

Related

Article author: Arthur Isaev

Banner image