Spring Boot 3.x upgrade. Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1
Asked Answered
S

8

85

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?

Secund answered 27/12, 2022 at 16:35 Comment(0)
P
222

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.

Priestridden answered 30/12, 2022 at 6:10 Comment(3)
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.Isoelectronic
In the era of ChatGPT, this is the best answer to this question.Eaddy
You can also choose "Project SDK" to delegate the responsibility to projectsCockerel
C
31

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

build.bradle file should contain either:

  1. under 'plugins' section: org.springframework.boot w/ ver. 3.x.x;
  2. under 'Java' section: 'sourceCompatibility' as version '17';
  3. File -> Settings -> Build, Execution, Deployment -> Gradle -> Gradle JVM: ver.17

or

  1. under 'plugins' section: org.springframework.boot w/ ver. 2.x.x;
  2. under 'Java' section: 'sourceCompatibility' as version '11';
  3. File -> Settings -> Build, Execution, Deployment -> Gradle -> Gradle JVM: ver.11
Candancecandela answered 3/1, 2023 at 10:56 Comment(3)
Yes. That's it. You either use Java 17 with Spring 3.0.x , or you use Java 11 with Spring 2.x.x. I used Java 11 + Spring 2.7.16Lucilius
Could you elaborate what we are supposed to change in Gradle build files to achieve this?Inspirational
@szx, inside build.gradle file you should have either 1) under 'plugins' section: org.springframework.boot w/ ver. 3.x.x; 2) under 'Java' section: 'sourceCompatibility' as version '17'; 3) File -> Settings -> Build, Execution, Deployment -> Gradle -> Gradle JVM: ver.17 or 1) under 'plugins' section: org.springframework.boot w/ ver. 2.x.x; 2) under 'Java' section: 'sourceCompatibility' as version '11'; 3) File -> Settings -> Build, Execution, Deployment -> Gradle -> Gradle JVM: ver.11Fillian
T
2

I had similar issue with a commandline, which I solved by ensuring that JAVA_HOME is correctly set to JDK17.

Treulich answered 19/9, 2023 at 12:33 Comment(0)
D
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'}
Delaware answered 28/12, 2022 at 2:50 Comment(2)
My goal is to upgrade to 3.0.1. The sample project just confirms the issue.Secund
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.Morlee
R
1

I had the same problem on ubuntu using ./gradlew build command and it turned out that it takes java version installed on my machine (which was 11 and it had to stay like that). I solved problem by adding org.gradle.java.home=pathToJava17 to gradle.properties file

Reeva answered 24/9, 2023 at 21:12 Comment(0)
L
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.

Lobar answered 17/3, 2023 at 14:12 Comment(0)
M
0

Change Gradle JVM version to 17 in IntelliJ. Ctrl + Alt + S --> Build, Execution, Deployment --> Gradle --> Gradle JVM --> java 17

Mesh answered 12/3 at 19:33 Comment(0)
C
-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

Chiffonier answered 4/4, 2023 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.