IntelliJ IDEA and Gradle

Introduction

IntelliJ IDEA is the IDE most Java teams use with Gradle. IDEA imports build.gradle, syncs dependencies, and exposes Gradle tasks in a tool window. This chapter covers installing IDEA, pointing it at your local Gradle (or Wrapper), and optionally reusing Maven’s local repository so dependencies download once across both tools.

Prerequisites

Install IntelliJ IDEA

  1. Download from https://www.jetbrains.com/idea/
  2. Run the installer (Windows/macOS) or unpack (Linux)
  3. On first launch, pick a theme and install the Java plugin bundle if prompted

Community Edition is enough for Gradle + Java learning. Ultimate adds Spring, Java EE, and advanced frameworks.

Open or Import a Gradle Project

  1. Welcome screen → Open (or File → Open)
  2. Select the project root that contains build.gradle or build.gradle.kts, or settings.gradle
  3. When asked, choose Open as Project (not “Open as File”)
  4. Wait for Gradle sync (progress bar bottom-right)

IDEA marks directories:

ColorMeaning
Bluesrc/main/java sources
Greensrc/test/java tests
Orangeresources

If src/main/java stays gray, sync failed—reload Gradle (below).

Configure Gradle in Settings

Open Settings / Preferences:

  • Windows/Linux: Ctrl + Alt + S
  • macOS: Cmd + ,

Go to Build, Execution, Deployment → Build Tools → Gradle.

For cloned team projects, select:

  • Gradle distribution: Wrapper

IDEA runs ./gradlew and uses the version pinned in gradle/wrapper/gradle-wrapper.properties. This matches CI.

Use Locally Installed Gradle (Learning / gradle init)

When bootstrapping new projects with a global install:

  • Gradle distribution: Local installation
  • Gradle home: your install path, for example:
PlatformExample GRADLE_HOME
WindowsD:\tools\gradle\gradle-8.12.1
macOS (Homebrew)/opt/homebrew/Cellar/gradle/8.12.1/libexec
macOS (SDKMAN)~/.sdkman/candidates/gradle/current
Linux (SDKMAN)~/.sdkman/candidates/gradle/current

Gradle JVM should be JDK 21 (Project SDK or explicit 21 path).

Use local Gradle installation in IntelliJ IDEA

Click ApplyOK, then reload the project.

Tip

Match the Command Line

The Gradle version in IDEA should match what gradle -version prints on your terminal. Mismatches cause “works in IDE, fails in CI” confusion—even when both succeed.

Delegate Build to Gradle

On the same Gradle settings page, enable:

  • Build and run using: Gradle
  • Run tests using: Gradle

Then Run and Build use the same classpath resolution as ./gradlew.

Share Maven’s Local Repository (Optional)

Maven caches artifacts under:

text
~/.m2/repository

Gradle normally caches under:

text
~/.gradle/caches/modules-2/files-2.1/...

To reuse JARs already downloaded by Maven, add mavenLocal() to repositories. A global hook is ~/.gradle/init.gradle:

Create the file if it does not exist, then sync in IDEA.

Warning

init.gradle affects all Gradle builds on your machine. For a single project only, put mavenLocal() inside that project’s build.gradle repositories { } block instead.

Per-project example:

gradle
repositories {
    mavenLocal()
    mavenCentral()
}

Gradle Tool Window

View → Tool Windows → Gradle (or the elephant icon on the right).

Useful sections:

  • Tasksbuild, test, clean, plugin tasks (application → run)
  • Dependencies — resolved graph; search and conflict hints
  • Reload — two arrows; click after editing build.gradle

Shortcut: Reload Gradle projectCtrl + Shift + O (Windows/Linux), Cmd + Shift + O (macOS).

Run and Debug Java Code

  1. Open a class with public static void main
  2. Click the green gutter icon → Run or Debug
  3. Or double-click application → run under Tasks (with application plugin)

Built-in terminal (Alt + F12 / Option + F12):

bash
./gradlew build
./gradlew test

On Windows:

bat
gradlew.bat build

Compare with Maven in IDEA

MavenGradle
Import filepom.xmlbuild.gradle / root folder
Tool windowMavenGradle
ReloadReload Maven projectReload Gradle project
CLI in terminalmvn./gradlew

FAQ

IDEA uses a different JDK than my terminal?

Set Gradle JVM to 21 in Gradle settings and Project SDK under Project Structure (Ctrl + Alt + Shift + S).

Sync failed: “Could not resolve…”

Check network, proxy, and repository blocks. Try ./gradlew build --refresh-dependencies in the terminal for the full error log.

Should I commit .idea?

Teams differ—many commit partial .idea files or use .gitignore. Always commit gradlew and gradle/wrapper/.

Bundled Gradle vs local?

Prefer Wrapper on shared repos. Use local only when learning gradle init before Wrapper exists.

What comes next?

Create your first Gradle project with gradle init and a tour of project files.