NoSuchMethodError:com.google.common.base.Preconditions.checkArgument

时间:2018-03-01 22:56:05

标签: guava google-cloud-pubsub

我一直收到这个错误:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V
    at com.google.cloud.pubsub.v1.Subscriber.<init>(Subscriber.java:138)
    at com.google.cloud.pubsub.v1.Subscriber.<init>(Subscriber.java:93)
    at com.google.cloud.pubsub.v1.Subscriber$Builder.build(Subscriber.java:623)
    at com.vanitysoft.payit.domain.dao.SubApp.main(SubApp.java:31)

我在我的pom.xml中有这个

    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-pubsub</artifactId>
        <version>0.32.0-beta</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.5-jre</version>
    </dependency>

是否可以分享google pub / sub的pom设置?我正在使用一个独立的应用程序。

1 个答案:

答案 0 :(得分:4)

com.google.cloud:google-cloud-pubsub:0.32.0-beta传递上需要com.google.guava:guava:jar:20.0但您已用新版本覆盖了番石榴。您可以通过运行mvn dependency:tree

来查看它
\- com.google.cloud:google-cloud-pubsub:jar:0.32.0-beta:compile
   +- io.netty:netty-tcnative-boringssl-static:jar:2.0.6.Final:compile
   +- com.google.cloud:google-cloud-core:jar:1.14.0:compile
   |  +- com.google.guava:guava:jar:20.0:compile
   |  +- joda-time:joda-time:jar:2.9.2:compile
   |  +- org.json:json:jar:20160810:compile
   |  +- com.google.http-client:google-http-client:jar:1.23.0:compile
   |  |  \- org.apache.httpcomponents:httpclient:jar:4.0.1:compile
   |  |     +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
   |  |     +- commons-logging:commons-logging:jar:1.1.1:compile
   |  |     \- commons-codec:commons-codec:jar:1.3:compile
   |  +- com.google.code.findbugs:jsr305:jar:3.0.0:compile
   |  +- com.google.api:api-common:jar:1.2.0:compile
   |  +- com.google.api:gax:jar:1.15.0:compile
   |  |  +- com.google.auto.value:auto-value:jar:1.2:compile
   |  |  +- org.threeten:threetenbp:jar:1.3.3:compile
   |  |  \- com.google.auth:google-auth-library-oauth2-http:jar:0.9.0:compile
   |  |     \- com.google.http-client:google-http-client-jackson2:jar:1.19.0:compile
   |  |        \- com.fasterxml.jackson.core:jackson-core:jar:2.1.3:compile
   |  +- com.google.protobuf:protobuf-java-util:jar:3.4.0:compile
   |  |  \- com.google.code.gson:gson:jar:2.7:compile
   |  +- com.google.api.grpc:proto-google-common-protos:jar:1.0.2:compile
   |  \- com.google.api.grpc:proto-google-iam-v1:jar:0.1.26:compile
   +- com.google.cloud:google-cloud-core-grpc:jar:1.14.0:compile
   |  +- com.google.auth:google-auth-library-credentials:jar:0.9.0:compile
   |  +- com.google.protobuf:protobuf-java:jar:3.4.0:compile
   |  +- io.grpc:grpc-protobuf:jar:1.7.0:compile
   |  |  \- io.grpc:grpc-protobuf-lite:jar:1.7.0:compile
   |  +- io.grpc:grpc-context:jar:1.7.0:compile
   |  \- com.google.api:gax-grpc:jar:1.15.0:compile
   +- com.google.api.grpc:proto-google-cloud-pubsub-v1:jar:0.1.26:compile
   +- com.google.api.grpc:grpc-google-cloud-pubsub-v1:jar:0.1.26:compile
   +- io.grpc:grpc-netty:jar:1.7.0:compile
   |  +- io.grpc:grpc-core:jar:1.7.0:compile (version selected from constraint [1.7.0,1.7.0])
   |  |  +- com.google.errorprone:error_prone_annotations:jar:2.0.19:compile
   |  |  +- com.google.instrumentation:instrumentation-api:jar:0.4.3:compile
   |  |  \- io.opencensus:opencensus-api:jar:0.6.0:compile
   |  +- io.netty:netty-codec-http2:jar:4.1.16.Final:compile (version selected from constraint [4.1.16.Final,4.1.16.Final])
   |  |  +- io.netty:netty-codec-http:jar:4.1.16.Final:compile
   |  |  |  \- io.netty:netty-codec:jar:4.1.16.Final:compile
   |  |  \- io.netty:netty-handler:jar:4.1.16.Final:compile
   |  |     \- io.netty:netty-buffer:jar:4.1.16.Final:compile
   |  |        \- io.netty:netty-common:jar:4.1.16.Final:compile
   |  \- io.netty:netty-handler-proxy:jar:4.1.16.Final:compile
   |     +- io.netty:netty-transport:jar:4.1.16.Final:compile
   |     |  \- io.netty:netty-resolver:jar:4.1.16.Final:compile
   |     \- io.netty:netty-codec-socks:jar:4.1.16.Final:compile
   +- io.grpc:grpc-stub:jar:1.7.0:compile
   \- io.grpc:grpc-auth:jar:1.7.0:compile

根据您的pom.xml代码段,您应该删除您的Guava版本,除非项目中的其他库需要此新版本。