Skip to content

Spring Boot 3 Gradle Plugin Java Version Error

Problem

When upgrading to Spring Boot 3.x and switching to Java 17, you might encounter a Gradle error during project import or build:

text
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
Required by:
    project : 
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 was found...
  - Incompatible because this component declares a component compatible with Java 17 
    and the consumer needed a component compatible with Java 11

Why This Happens

Spring Boot 3 requires Java 17, but the error indicates your Gradle build is using Java 11. This incompatibility occurs because:

  1. The Spring Boot Gradle plugin 3.x is built for Java 17
  2. Your Gradle daemon/JVM is running on Java 11 (or older)
  3. Your build.gradle.kts specifies Java 17, but Gradle executes using Java 11

Solutions

This ensures IntelliJ uses Java 17 for Gradle operations:

  1. Open Settings (Ctrl + Alt + S or Cmd + , on macOS)
  2. Navigate to: Build, Execution, Deployment → Build Tools → Gradle
  3. Under Gradle Projects, select your project
  4. Set Gradle JVM to a JDK 17 installation

TIP

Refresh Gradle projects after making changes (Gradle toolbar → Refresh icon)

2. Set JAVA_HOME Environment Variable

Configure your system to use Java 17 globally:

  • Windows:

    powershell
    $env:JAVA_HOME = "C:\path\to\jdk-17"
    # Add to system PATH
    $env:Path = "$env:JAVA_HOME\bin;$env:Path"
  • Linux/macOS:

    bash
    export JAVA_HOME=/path/to/jdk-17
    export PATH=$JAVA_HOME/bin:$PATH

3. Configure gradle.properties

Add this to your project's gradle.properties file:

properties
org.gradle.java.home=/path/to/jdk-17

4. Verify Build Configuration

Ensure these settings exist in your build.gradle.kts:

kotlin
plugins {
    id("org.springframework.boot") version "3.0.1"  // Must be 3.x
}

java {
    sourceCompatibility = JavaVersion.VERSION_17  // Must be VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "17"  // Must match Java version
}

Explanation

Why Java 17 Matters

Spring Boot 3.x requires Java 17 as the minimum version. The Gradle plugin must run on JVM 17+ because:

  • The plugin contains Java 17 bytecode
  • It uses Java 17 APIs unavailable in older versions
  • Gradle requires runtime version matching the plugin's target

Common Mistakes

  • Incorrect Gradle JVM: IDE defaults to system Java (often older than 17)
  • Mixed JDKs: Multiple JDKs installed without clear configuration
  • Kotlin configuration: jvmTarget set to lower than 17

WARNING

Spring Boot 3 is incompatible with Java 11. Downgrading to Spring Boot 2.x (version "2.7.x") will keep Java 11 compatibility but sacrifices Spring Boot 3 features.

Final Verification

Confirm your setup with this command:

bash
./gradlew --version

Check output includes:

text
JVM:          17.x.x (Vendor)

When all settings are correct:

  • Gradle tasks execute with Java 17
  • Spring Boot Gradle plugin resolves successfully
  • Project imports and builds without errors