in intelliJ spring boot gradle plugin 3.0.0 no matching variant found

34.4k Views Asked by At

I'm trying to use version 3.0.0 of the spring boot Gradle plugin. Here's my build.gradle.kts file:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "3.0.0"
    id("io.spring.dependency-management") version "1.1.0"
    kotlin("jvm") version "1.7.20"
    kotlin("plugin.spring") version "1.7.20"
    id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
}

java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    runtimeOnly("org.postgresql:postgresql")
    runtimeOnly("org.postgresql:r2dbc-postgresql")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("io.projectreactor:reactor-test")
    jdbc("org.postgresql:postgresql:42.5.0")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

I'm getting the error pasted below. I know it's not a network issue because when I change the version to 2.7.6, the error goes away.

> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.0
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5.1' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
5

There are 5 best solutions below

7
Mag Musik On BEST ANSWER

enter image description hereUnder IntelliJ => Preferences => Build, execution, deployment => Gradle, I had to set the Gradle JVM to: Project SDK (17).

I'm not sure why 2.7.6 & 2.7.1 spring boot plugin version worked w/ the Gradle JVM being set to Java 11… It appears as if spring boot Gradle plugin 3.0.0 is stricter.

1
nightlytrails On

From the Spring Boot Getting Started docs -

Spring Boot 3.0.3 requires Java 17 and is compatible up to and including Java 19.

In my case, I already had Gradle JVM to: Project SDK (17) And then I had to update

java.sourceCompatibility = JavaVersion.VERSION_17

as well in module build.gradle.kts

Earlier it was set to JavaVersion.VERSION_11

3
Renju Jose On

Even in my case, the project SDK was set properly but weirdly IntelliJ decided the modules won't respect that. I checked the module settings and it was showing as No SDK.

Updated the module SDK and click Apply. The problem is gone.

Module settings in IntelliJ - shows language level - Java 17

Module dependencies in IntelliJ - shows Module SDK - No SDK

@mag-musik's pointer helped me check in the right place.

0
Miguel Marques On

In my case, using Windows, the problem was that my JAVA_HOME was still pointing to a JDK 14 instead of 17.

0
Jishnu S On

I think we can all agree that this definitely is a JDK version issue. If you are using intellij then this might help you.

I fixed the issue by changing the jdk version in project structure settings and also change the java version used by the build tool (in my case it was gradle). You can find this config under intellij settings.

The window would look something like this:-

enter image description here