in intelliJ spring boot gradle plugin 3.0.0 no matching variant found
Asked Answered
T

5

41

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')
Thrawn answered 22/12, 2022 at 15:2 Comment(0)
T
132

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.

Thrawn answered 22/12, 2022 at 19:29 Comment(7)
Thanks for posting the answer to your question so that other readers can enjoy it in the future! Don't forget to mark your answer as accepted: this helps in maintaining Stackoverflow of high quality :)Thunderpeal
@Thunderpeal of course. Hopefully this saves someone else the time I spent tracking this down. :-)Thrawn
I have the same issue and this hasn't resolved it unfortunately.Epstein
i had to google around for a while as there are multiple causes to this error message. i hope you were able to find your own cause.Thrawn
Thanks for sharing the solution - works for me as well on a project where there is sourceCompatibility=17 specified in "gradle.properties". So the cause of the problem seems to be that IDEA doesn't automatically set the correct Gradle JVM based on the content of Gradle configuration files?Hast
@PetrBodnár that does appear to be the problemThrawn
Thanks @MagMusik for posting the answer to your question so that other readers can enjoy it in the future! Don't forget to mark your answer as accepted: this helps in maintaining Stackoverflow of high quality :)Agincourt
C
5

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

Clematis answered 1/6, 2023 at 15:30 Comment(0)
S
4

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

Stypsis answered 18/8, 2023 at 7:11 Comment(0)
S
3

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

Swimming answered 28/2, 2023 at 13:18 Comment(1)
in the question the property was already set to java version 17.Thrawn
G
1

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.

Guitarfish answered 22/4, 2023 at 6:5 Comment(3)
you're doing the over all project SDK. not the jvm for gradle. i'm going to update my answer with a screen shot so it's more clear.Thrawn
Actually, your answer pointed me to check in the IDE settings(was already set to project SDK) and then in the project settings. My issue was in project settings > module settings. However, your new screenshot will definitely help someone who has issue in IDE settings. :DGuitarfish
glad it helped. when i had my problem, the error i saw had a number of root causes so i thought i should save someone else this experience.Thrawn

© 2022 - 2024 — McMap. All rights reserved.