gradle 如何解决java spring Boot 项目中的类路径冲突

2uluyalo  于 2022-11-14  发布在  Java
关注(0)|答案(1)|浏览(248)
java.lang.NoSuchMethodError: io.grpc.NameResolverProvider.getScheme()Ljava/lang/String;
    at io.grpc.NameResolverRegistry.refreshProviders(NameResolverRegistry.java:96) ~[grpc-api-1.42.2.jar:3.4.7]
    at io.grpc.NameResolverRegistry.getDefaultRegistry(NameResolverRegistry.java:131) ~[grpc-api-1.42.2.jar:3.4.7]
    at net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration.grpcNameResolverRegistration(GrpcClientAutoConfiguration.java:119) ~[grpc-client-spring-boot-autoconfigure-2.13.1.RELEASE.jar:2.13.1.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_321]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_321]

2022-11-10 17:22:36.290 ERROR 21408 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Action:

Correct the classpath of your application so that it contains compatible versions of the classes io.grpc.NameResolverRegistry and io.grpc.NameResolverProvider

Process finished with exit code 0

说明:
试图调用一个不存在的方法。尝试是从以下位置进行的:

io.grpc.NameResolverRegistry.refreshProviders(NameResolverRegistry.java:96)

下列方法不存在:

io.grpc.NameResolverProvider.getScheme()Ljava/lang/String;

呼叫方法的类别io.grpc.NameResolverRegistry是从下列位置载入的:

jar:file:/C:/Users/Bashlaw/.gradle/caches/modules-2/files-2.1/io.grpc/grpc-api/1.42.2/dd67a2446043d3903f7e0532d17b8bd2f1bfe67a/grpc-api-1.42.2.jar!/io/grpc/NameResolverRegistry.class

被调用方法的类io.grpc.NameResolverProvider可从以下位置获得:

jar:file:/C:/Users/Bashlaw/.gradle/caches/modules-2/files-2.1/com.github.AfricasTalkingLtd.africastalking-java/core/3.4.8/dba39ba2047b38c53c9e645d535a1db6c1164219/core-3.4.8.jar!/io/grpc/NameResolverProvider.class
jar:file:/C:/Users/Bashlaw/.gradle/caches/modules-2/files-2.1/io.grpc/grpc-api/1.42.2/dd67a2446043d3903f7e0532d17b8bd2f1bfe67a/grpc-api-1.42.2.jar!/io/grpc/NameResolverProvider.class

被调用方法的类层次结构是从以下位置加载的:

io.grpc.NameResolverProvider: file:/C:/Users/Bashlaw/.gradle/caches/modules-2/files-2.1/com.github.AfricasTalkingLtd.africastalking-java/core/3.4.8/dba39ba2047b38c53c9e645d535a1db6c1164219/core-3.4.8.jar
io.grpc.NameResolver.Factory: file:/C:/Users/Bashlaw/.gradle/caches/modules-2/files-2.1/com.github.AfricasTalkingLtd.africastalking-java/core/3.4.8/dba39ba2047b38c53c9e645d535a1db6c1164219/core-3.4.8.jar

我试图排除gradle上的路径,但仍然得到类路径冲突错误。我将感谢您的帮助:

91zkwejq

91zkwejq1#

com.github.AfricasTalkingLtd.africastalking-java:core依赖项是作为一个应用程序构建的,这意味着它包含了它的所有依赖项--这就是所谓的uber-JAR。
由于core依赖项只包含一个类,它只提供了一个main方法,请尝试将其替换为单独的模块。core包含以下模块:

compile project(":airtime")
compile project(":payment")
compile project(":sms")
compile project(":ussd")
compile project(":voice")
compile project(":token")
compile project(":server")
compile project(":application")

包含了你需要的模块,你的问题就解决了-- gRPC是从它自己的依赖项中包含的,而不是从这个core依赖项中包含的。如果你省略了不需要的模块,你的应用程序也会变得更小。

相关问题