首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring从2.4.x升级到2.5.x后面对NoSuchMethodError和NoClassDefFoundError

Spring从2.4.x升级到2.5.x后面对NoSuchMethodError和NoClassDefFoundError
EN

Stack Overflow用户
提问于 2022-05-09 16:08:56
回答 1查看 446关注 0票数 0

运行gradle清洁生成时记录错误

代码语言:javascript
复制
java.lang.Exception: Unexpected exception, expected<org.springframework.web.client.HttpClientErrorException> but was<java.lang.NoSuchMethodError>
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:30)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)

致因: kotlin.collections.MapsKt.createMapBuilder()Ljava/util/Map;:kotlin.reflect.jvm.internal.impl.descriptors.Visibilities.(Visibilities.kt:56) at kotlin.reflect.jvm.internal.impl.descriptors.Visibility.compareTo(Visibility.kt:23) at kotlin.reflect.jvm.internal.impl.descriptors.DescriptorVisibility.compareTo(DescriptorVisibility.kt:66)

build.gradle

代码语言:javascript
复制
buildscript {
    ext.kotlin_version = '1.6.21' // Required for Kotlin integration  
    ext.spring_boot_version = '2.6.6'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Required for Kotlin integration
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin' // Required for Kotlin integration
apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
apply plugin: "jacoco"

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}" // Required for Kotlin integration
    implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}"
   // implementation 'org.springframework.boot:spring-boot-starter-parent:2.6.7'
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-jdbc"    
    testImplementation "org.springframework.boot:spring-boot-starter-test"
    testImplementation 'com.github.tomakehurst:wiremock-standalone:2.27.2'
    testImplementation 'info.cukes:cucumber-spring:1.2.6'
    testImplementation 'info.cukes:cucumber-junit:1.2.6'   
    implementation 'com.google.code.gson:gson:2.9.0'
    // end::tests[]
}
EN

回答 1

Stack Overflow用户

发布于 2022-08-24 10:55:26

您一定是在使用Kotlin的旧版本,也许是1.3。某些依赖项导致代码使用此降级版本。请查看外部库,您将能够找到1.6.211.3.11版本的kotlin-stdlib

MapKt.createMapBuilder存在于1.6版本中,而不是1.3版本中。

运行./gradlew appname:dependencies并查看哪些依赖项正在使用此依赖项。

会有这样的事情

kotlin-stdlib-1.6.21--->1.3.21 (或11或其他版本)

如果是这种情况,则需要查看依赖关系洞察力,以查看使用此prev版本的依赖项:即1.3

您可以运行cd ~/.gradle/caches/modules-2/files-2.1

搜索此版本号:

grep -r "1.3.11"

在我的例子中,kotlin-stdlib的版本是1.3.11

您将能够找到导致降级发生的依赖关系。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72175041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档