NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V

什么Google Maven依赖项可以修复此错误:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:487)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
    at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
    at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
    at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
    at java.io.InputStream.read(InputStream.java:101)

法典:

Blob blob = storage.get(blobId);
if(blob.exists()) {
    return true;
}

答案 1

您的Google番石榴版本可能太旧(<20.0)或不匹配(多个jar版本)。确保依赖项树中有多个版本。

mvn dependency:tree | less

寻找番石榴版本。


答案 2

请将以下依赖项添加到项目的 POM 中:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.6-jre</version>
</dependency> 
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.8</version>
</dependency>

推荐