37

I recently wanted to upgrade my kotlin project from spring boot 2.7.x to 3.0.1. I use Java 17 temurin, gradle 7.6. In IntelliJ I got following error message on importing the project over gradle:

A problem occurred configuring root project 'demo'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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.6' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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.6')
          - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
          - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 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.6')
          - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
          - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
          - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')

I also tried to download a similar project skeleton from start.spring.io. With following build.gradle.kts:

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

plugins {
    id("org.springframework.boot") version "3.0.1"
    id("io.spring.dependency-management") version "1.1.0"
    kotlin("jvm") version "1.7.22"
    kotlin("plugin.spring") version "1.7.22"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

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

tasks.withType<Test> {
    useJUnitPlatform()
}

But the error message on importing the projekt remains the same. Any ideas?

Roman T
  • 1,400
  • 5
  • 18
  • 31

5 Answers5

116

I see you're using IntelliJ IDEA for this. This is what worked for me: Go to the settings --> Build, Execution, Deployment --> Build Tools --> Gradle. Click on your gradle project under 'Gradle Projects'. Choose your Gradle JVM for the project... in my case it was openjdk-19. Now it should work.

TomCat
  • 1,176
  • 1
  • 2
  • 2
  • 1
    A "different way to do this". (and a bigger hammer if this answer small hammer does not work) If (or make sure) your JAVA_HOME is pointed to the 'correct' JDK (JDK17 for the original question). Close IntelliJ (all instances). Delete the ".idea" folder. Reload the project in IntelliJ. This will "rework" the .idea folder to point to JDK17. (Note, this answer is basically changing one item inside what is stored in the .idea folder). Again, try this answer first. But this comment is provided as a bigger hammer. – granadaCoder May 10 '23 at 17:48
  • 1
    In the era of ChatGPT, this is the best answer to this question. – Ariful Haque Jun 21 '23 at 08:54
8

Spring Boot 3.0 requires Java 17. Read this blog for more information.

Jay Shah
  • 161
  • 1
  • 2
1

It seems there is a problem with springboot 3.0.1 once you downgrade to 2.7.1 gradle will build just fine.

As you are with a sample project, just try change your gradle file as follows:

plugins {
id 'java'
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.1.0'}
  • 2
    My goal is to upgrade to 3.0.1. The sample project just confirms the issue. – Roman T Dec 28 '22 at 08:48
  • 1
    check your java version on your terminal. probably your version is set to 11 even though your project is configured to java 17. I had the same issue while executing gradle commands through the terminal, I got this issue. It was due to my java version being set to 11. after I changed to 17 gradle perfectly. – Nimantha Mar 05 '23 at 05:35
0

Try to set the java plugin version as following:

 subprojects {
  apply plugin: "java"
  apply plugin: "groovy"
  apply plugin: 'idea'

  group project.parent.group
  version project.parent.version
  sourceCompatibility = 17
  targetCompatibility =17

Also, you can check if the java version you are using is the one required by the project by going to File -> Project Structure -> Project Settings - Project.

-1

I switched to newer version of eclipse and this error disappeared - Here is newer version which did not had this issue -

Version: 2023-03 (4.27.0) Build id: 20230309-1520

Kiran Pawar
  • 79
  • 1
  • 8