-2

I am developing a spring-boot project. This project should be integrated with React, so, from any reasons I have to use exactly 2.2.4 spring-boot. But in this case, I can't build project because I am receiving error Unsupported class file major version 61.

So, my gradle.build:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.1.0'
}

tasks.withType(JavaCompile) {
    sourceCompatibility = '17'
    targetCompatibility = '17'
}

group = 'com.hrzc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

ext {
    lombok_version = '1.18.24'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    //lombok
    compileOnly "org.projectlombok:lombok:${lombok_version}"
    runtimeOnly "org.projectlombok:lombok:${lombok_version}"
    annotationProcessor "org.projectlombok:lombok:${lombok_version}"
}

tasks.named('test') {
    useJUnitPlatform()
}

I use java 17: java --version:

openjdk 17.0.6 2023-01-17 LTS OpenJDK Runtime Environment
Corretto-17.0.6.10.1 (build 17.0.6+10-LTS) OpenJDK 64-Bit Server VM
Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)

javac --version:

javac 17.0.6

And gradle 7.5:

gradle --version:

Gradle 7.5

Build time: 2022-07-14 12:48:15 UTC Revision:
c7db7b958189ad2b0c1472b6fe663e6d654a5103

Kotlin: 1.6.21 Groovy: 3.0.10 Ant: Apache Ant(TM)
version 1.10.11 compiled on July 10 2021 JVM: 17.0.6
(Amazon.com Inc. 17.0.6+10-LTS) OS: Windows 10 10.0 amd64


Why do I am receiving error:

Unsupported class file major version 61

Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59
  • What about `javac -version`? – g00se Jun 09 '23 at 18:46
  • @g00se I have updated answer: 17.0.6 – Valentyn Hruzytskyi Jun 09 '23 at 18:50
  • Strange. Personally I don't do Gradle but somehow it *seems* a compiler (or runtime) < 17 is being used – g00se Jun 09 '23 at 20:07
  • 3
    Your problem is that you are using Spring Boot 2.2.4 with Java 17. Either downgrade your Java version, or upgrade your Spring Boot version. [From this accepted SO answer](https://stackoverflow.com/a/75503865/2985643): _"Spring Boot 2.5 is minimal version that supports JRE 17."_ There is probably a helpful matrix documenting the JDKs supported/required for each Spring Boot version somewhere, but I can't find it. – skomisa Jun 10 '23 at 00:24
  • 2
    ...Also, I couldn't find release notes specific to release 2.2.4, but I did find this in [the Spring Boot documentation for 2.2.x](https://docs.spring.io/spring-boot/docs/2.2.x/reference/html/getting-started.html#getting-started.system-requirements): _"Spring Boot 2.2.13.RELEASE requires Java 8 and is compatible up to Java 15 (included)."_ So you definitely can't use a JDK >= 15 with 2.2.4, and it might even be lower than 15. – skomisa Jun 10 '23 at 00:33
  • @skomisa You are right. I had updated spring-framework version to 2.7.3 and now all works well. – Valentyn Hruzytskyi Jun 12 '23 at 12:21
  • Does this answer your question? [What minimal Spring Boot 2.x version can run for sure on Java 17?](https://stackoverflow.com/questions/75503517/what-minimal-spring-boot-2-x-version-can-run-for-sure-on-java-17) – spamove Jul 19 '23 at 19:56

1 Answers1

1

Since I used an example to investigate the node and npm integration to the spring project I used the same spring-framework version as in their repository (2.2.4). But I didn't consider that this version isn't compatible with Java 17. Thanks to @skomisa tip I only updated the spring version to 2.7.3 and it all.

plugins {
    id 'org.springframework.boot' version '2.7.3'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'java'
}
Valentyn Hruzytskyi
  • 1,772
  • 5
  • 27
  • 59