1

I have an app that was migrated to Spring Boot 3.1.0 and Java 17. Now I'm trying to make it working together with Spring 6.0.9 (before that, as you may see in the commented dependencies, it had explicitly downgraded Spring version because o history of the versions upgrade.

So, when I try to run bootRun fo rth econfiguration,

buildscript {
    ext {
        springBootVersion = '3.1.0'
    }

    repositories {
        maven {
            url "https://nexus.dev.domoy.ru/repository/mvn-remote/"
        }
        maven {
            url "https://nexus.dev.domoy.ru/repository/gradle-remote-plugins/"
        }
        maven {
            credentials {
                username "$mavenUser"
                password "$mavenPassword"
            }
            url "$mavenUrl"
        }       
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1"
        classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
    }


    
}


apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
apply plugin: 'com.github.ManifestClasspath'

group = 'rf.dom.billing'
archivesBaseName = 'billing-ap'
version = '1.0.5'

mainClassName = 'rf.dom.billing.ap.Application'

sourceCompatibility = 1.17
targetCompatibility = 1.17

repositories {
    maven {
        url "https://nexus.dev.domoy.ru/repository/mvn-remote/"
    }
    maven {
            url "https://nexus.dev.domoy.ru/repository/gradle-remote-plugins/"
        }
    maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
            url "$mavenUrl"
    }
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Hoxton.SR10"
    }
}

//sonarqube {
//    properties {
//        property "sonar.host.url", "https://sonarqube.domoy.ru/sonarqube"
//        property "sonar.login", "83f2b4d2c20b87a6f96385bb947d3531dbd4ba8e"
//        property "sonar.projectKey", "billing-ap"
//        property "sonar.projectName", "BILLING-ap"
//        property "sonar.exclusions",  "**/dto/**/*.java"
//    }
//}

jacoco {
    toolVersion = "0.8.8"
}

bootRun {
    systemProperties System.properties
    systemProperties.remove("java.endorsed.dirs")
}

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/generated/java']
        }
    }
}

configurations {

    bouncyCastle
    runtime.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
    compile.exclude group: "net.sf.ehcache"

    all {
        resolutionStrategy {
            // Force jackson 2.4.4 for Spark
            force 'com.fasterxml.jackson.core:jackson-core:2.13.5', 'com.fasterxml.jackson.core:jackson-databind:2.13.5', 'com.fasterxml.jackson.core:jackson-annotations:2.13.5'
        }
    }
}


task copyCoreJarsToLibs(type: Copy, dependsOn: jar) {
    from "build/libs"
    into "${rootDir}/artifacts/docker/billing_ap"
    exclude '*.original', '*replicator*'
}

task copyDockerfiles(type: Copy) {
    from "${rootDir}/dockerfile"
    into "${rootDir}/artifacts/docker/billing_ap"
}

task copyDockerfilesProd(type: Copy) {
    from "${rootDir}/dockerfile/Dockerfile-prod"
    into "${rootDir}/artifacts/docker/billing_ap"
    rename { String fileName ->
        fileName.replace("Dockerfile-prod",
                "Dockerfile")
    }
}

task collectArtifacts {
    dependsOn(build, copyCoreJarsToLibs, copyDockerfiles)
}

task collectArtifactsProd {
    dependsOn(build, copyCoreJarsToLibs, copyDockerfilesProd)
}

ext['elasticsearch.version'] = '7.2.0'


dependencies {

    implementation 'javax.validation:validation-api:2.0.1.Final'

    implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-webflux:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-mail:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-oauth2-client:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server:${springBootVersion}"
    implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}") {
    //    exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
    }
    implementation "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
    //implementation "org.springframework.boot:spring-boot-actuator-autoconfigure:${springBootVersion}"
    //implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"

    runtime 'io.micrometer:micrometer-registry-prometheus'

//    implementation 'org.springframework.amqp:spring-amqp:2.3.11'
//    implementation 'org.springframework.boot:spring-boot-starter-undertow'
//    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
//    implementation 'org.springframework.security:spring-security-oauth2-jose:5.5.7'
//    implementation 'org.springframework.security:spring-security-oauth2-core:5.5.7'
//    implementation 'org.springframework.security:spring-security-core:5.5.7'
//    implementation 'org.springframework.security:spring-security-web:5.5.7'
//    implementation 'org.springframework.security:spring-security-oauth2-client:5.7.5'
//    implementation 'org.springframework.security:spring-security-oauth2-resource-server:5.5.7'
//    implementation 'org.springframework:spring-core:6.0.9'
//    implementation 'org.springframework:spring-beans:6.0.9'
//    implementation 'org.springframework:spring-expression:6.0.9'
//    implementation 'org.springframework:spring-webflux:6.0.9'
//    implementation 'org.springframework:spring-webmvc:6.0.9'
//    implementation 'org.springframework:spring-web:6.0.9'


    implementation 'io.projectreactor:reactor-core:3.2.12.RELEASE'

    compileOnly 'org.projectlombok:lombok:1.18.22+'
    annotationProcessor 'org.projectlombok:lombok:1.18.22+'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.22+'
    annotationProcessor 'org.hibernate:hibernate-jpamodelgen:5.4.4.Final'

    implementation 'org.postgresql:postgresql:42.2.8'
    implementation 'com.zaxxer:HikariCP:3.4.0'
    //implementation 'org.flywaydb:flyway-core:5.2.4'


    implementation 'org.hibernate.javax.persistence:hibernate-jpa-2.2-api:1.0.0.Beta2'

    implementation 'net.bull.javamelody:javamelody-spring-boot-starter:1.79.0'

    implementation 'commons-io:commons-io:2.6'

    implementation 'io.springfox:springfox-swagger2:3.0.0'
//
//            {
//        exclude module: 'swagger-annotations'
//        exclude module: 'swagger-models'
//    }
    //implementation 'io.swagger:swagger-annotations:1.5.23'
    //implementation 'io.swagger:swagger-models:1.5.23'
    implementation 'io.springfox:springfox-swagger-ui:3.0.0'

    implementation 'rf.dom.billing:billing-model:RELEASE.2.2.49'
    implementation ('rf.dom.billing:billing-common:RELEASE.1.0.6')
            {
                exclude group: 'bouncycastle', module: 'bcprov-jdk14'
            }
    implementation 'rf.dom.billing:billing-tracking:RELEASE.1.1.13'
    implementation 'rf.dom.billing:billing-docstore-integration:1.0.3'

    /*Cloud start*/
    implementation 'org.springframework.cloud:spring-cloud-starter-config:2.1+'
    implementation 'org.springframework.cloud:spring-cloud-starter:2.1+'
    implementation 'org.springframework.cloud:spring-cloud-config-client:2.1+'
    /*Cloud end*/

    implementation 'org.jxls:jxls-poi:1.2.0'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.boot:spring-boot-starter-undertow'
    testImplementation 'org.testng:testng:6.14.3'
    testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
    testImplementation 'com.opentable.components:otj-pg-embedded:0.13.1'
    testImplementation 'org.flywaydb:flyway-core:5.2.4'

    //trivy
//    implementation 'ch.qos.logback:logback-core:1.2.9'
//    implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.5'
//    implementation 'com.fasterxml.jackson.core:jackson-core:2.13.5'
//    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.5'
//    implementation 'com.google.guava:guava:30.0-jre'
//    //implementation 'com.nimbusds:nimbus-jose-jwt:7.9'
//    implementation 'com.nimbusds:nimbus-jose-jwt:8.21'
//    implementation 'com.nimbusds:oauth2-oidc-sdk:9.19'
//    implementation 'commons-io:commons-io:2.7'
//
//    implementation 'io.netty:netty-codec:4.1.77.Final'
//    implementation 'io.netty:netty-codec-http:4.1.77.Final'
//    implementation 'io.netty:netty-codec-http2:4.1.77.Final'
//    implementation 'io.netty:netty-codec-socks:4.1.77.Final'
//    implementation 'io.netty:netty-handler:4.1.77.Final'
////
//    implementation 'io.undertow:undertow-core:2.2.19.Final'
//    implementation 'net.minidev:json-smart:2.4.9'
//    implementation 'org.apache.commons:commons-compress:1.21'
//    implementation 'org.apache.httpcomponents:httpclient:4.5.13'
//    implementation 'org.apache.poi:poi:5.2.1'
//    implementation 'org.apache.poi:poi-ooxml:5.2.1'
//    implementation 'org.bouncycastle:bcprov-jdk14:1.73'
//    //implementation 'bouncycastle:bcprov-jdk14:161'
//    //implementation 'bouncycastle:bcprov-jdk14:161'
//    implementation 'org.bouncycastle:bcprov-jdk15on:1.67'
//    implementation 'org.elasticsearch:elasticsearch:7.9.2'
//    implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.9.2'
//    implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.9.2'
//    implementation 'org.eclipse.jetty:jetty-util:11.0.15'
////    implementation 'org.dom4j:dom4j:2.1.3'
//    implementation 'org.eclipse.jetty:jetty-http:11.0.15'
//    implementation 'org.eclipse.jetty:jetty-io:11.0.15'
//    implementation 'org.hibernate.validator:hibernate-validator:6.0.20.Final'
//    implementation 'org.postgresql:postgresql:42.5.1'
//    implementation 'org.yaml:snakeyaml:1.33'
//    implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
//    implementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.69'

    bouncyCastle 'org.bouncycastle:bcprov-jdk14:1.73'

    compileOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0'
}

task installBouncyCastleJar {
    doLast {
        def bcFile = file('build/libs/bcprov-jdk14-1.73.jar')
        def groupId = 'bouncycastle'
        def artifactId = 'bcprov-jdk14'
        def version = '173'
        def packaging = 'jar'

//        project.repositories.maven.install([
//                file: bcFile,
//                groupId: groupId,
//                artifactId: artifactId,
//                version: version,
//                packaging: packaging
//        ])
    }
}

project.afterEvaluate {
    build.dependsOn(installBouncyCastleJar)
}

tasks.withType(JavaCompile) {
    options.annotationProcessorGeneratedSourcesDirectory = file("src/generated/java")
}

wrapper {
    distributionType = Wrapper.DistributionType.ALL
    gradleVersion = '6.0'
}

test {
    // enable TestNG support (default is JUnit)
    useTestNG()
    testLogging.showStandardStreams = true
    testLogging.exceptionFormat = 'full'
}

task printName {
    doLast {
        print project.name
    }
}

task printVersion {
    doLast {
        print project.version
    }
}

I'm getting the below problkem, while the app is on 17th kava, gradle is ran on 17th java and nothing may require the above Java version?

2023-06-12 18:36:20.466 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
2023-06-12 18:36:20.475 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:452)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:315)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:276)
    at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
    at 

    org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at rf.dom.billing.ap.Application.main(Application.java:24)
    Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
    Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [D:\Java\domrf2\build\classes\java\main\rf\dom\billing\ap\Application.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
    
        at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:60)
        at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
        at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
        at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
        at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:429)
        ... 21 common frames omitted
    Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
        at org.springframework.asm.ClassReader.<init>(ClassReader.java:196)
        at org.springframework.asm.ClassReader.<init>(ClassReader.java:177)
        at org.springframework.asm.ClassReader.<init>(ClassReader.java:163)
        at org.springframework.asm.ClassReader.<init>(ClassReader.java:284)
        at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:57)
        ... 25 common frames omitted
    
    Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
    
    Execution failed for task ':bootRun'.
    > Process 'command 'D:\Java\jdk-17.0.2\bin\java.exe'' finished with non-zero exit value 1

UPD after updating ASM to 9.5 still getting the problem:

enter image description here

Eljah
  • 4,188
  • 4
  • 41
  • 85
  • Class version 61 is Java 17, so you are probably running something older. – Jorn Jun 12 '23 at 15:49
  • https://stackoverflow.com/search?q=Unsupported+class+file+major+version – fantaghirocco Jun 12 '23 at 16:02
  • 1
    Your dependencies want to make me cry... There are too many and there are too many for which you workaround the Spring Boot / Spring Cloud dependency management. Also Spring Cloud Hoxton is for Spring Boot 2.2/2.3 so that will pull in old incompatible stuff. Also adding `javax.validation`/`persistence-api` is the wrong thing you need to migrate to JakartaEE. – M. Deinum Jun 12 '23 at 17:41

1 Answers1

1

You probably are using a too old version of Java ASM.

According to the versions list you need at least version 9.1 to support Java 17.

See answers to this SO question to find out which dependency is using the outdated ASM version: Using Gradle to find dependency tree

I also saw that you are referring to Gradle version 6, this could also be a problem. Please try to update it to a more recent version, since Gradle itself also is using ASM. The Gradle compatibility chart shows that you need at least version 7.3 to support Java 17

cyberbrain
  • 3,433
  • 1
  • 12
  • 22
  • I have upgrated accordilgly, but still getting the same error – Eljah Jun 12 '23 at 17:36
  • could you please check the last version of the question. I have upgraded the Asm and Gradle is 7.5, but still getting the same error. Have no idea, why not needed ASM is called during the runtime. See the Gradle dependency output, attached as a screenshot. – Eljah Jun 13 '23 at 06:56
  • maybe a silly question but sometimes you don't think of simple solutions: did you clear your build results folder and run a fresh rebuild over all components? – cyberbrain Jun 13 '23 at 07:16
  • good question, but not, I checked that. does Gradle dependency tool checks for all Gradle plugins too? Can't some plugin still use older `asm` under the hood? – Eljah Jun 13 '23 at 10:54
  • 1
    I didn't try it by myself, but this page on developing Gradle plugins tells how to show plugin dependencies: [Designing Gradle plugins#Minimizing the use of external libraries](https://docs.gradle.org/7.3/userguide/designing_gradle_plugins.html#minimizing_the_use_of_external_libraries) – cyberbrain Jun 13 '23 at 12:10
  • 1
    A more desperate approach also could be to delete your gradle cache folder - not that I expect anything really helpful, more as an action to work really step by step – cyberbrain Jun 13 '23 at 12:13