![](/img/trans.png)
[英]NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
[英]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;
}
您的 Google 番石榴版本太舊 (< 20.0) 或不匹配(多個 jars 版本)。 確保您的依賴樹中沒有多個版本。
使用
mvn dependency:tree | less
尋找番石榴版本。
請將以下依賴項添加到您項目的 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>
就我而言,我碰巧包括了兩者
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
和
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
事實證明,我不能同時使用這兩個庫。 刪除 google-collections 為我解決了這個問題。
嘗試在包含項目的 pom.xml 中的依賴項頂部插入包含較新版本番石榴的依賴項。
例如
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.1.1-jre</version>
</dependency>
我在 Java/Kotlin 應用程序中遇到了同樣的問題。 當應用程序通過 IntelliJ 運行時,沒有任何問題。 但是,當.Jar運行時,上面的錯誤消息被拋出。
對於上面@Laurent Perez 定義的 Guava 問題,我找不到要采取的直接操作項,因此我執行了以下操作,解決了運行.Jar文件的問題:
如果上述方法不起作用,請嘗試其他操作:
對於遇到這樣的事情的任何人,我有以下 pom:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
</dependency>
並注釋掉 maven-shade 插件為我修復了它......
當您的依賴項中缺少番石榴庫時,就會發生這種情況。 在 pom.xml 中使用以下添加它
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
另一個原因可能是 google guava/collection 庫有多個版本,你不能同時擁有@sabbir 在他的評論中提到的兩個版本,你應該刪除其中一個。
最后,可能是其他一些依賴項依賴於以前版本的 google guava/collections。 轉到 Dependency Hierarchy 並搜索 google 並查看所有依賴項都依賴於以前的版本。 在我的情況下,它是由 version-maven-plugin,版本 2.7
這里version-maven-plugin,2.7版使用google collections 1.0,我需要guava 24.0 兩者不能同時工作。
我像這樣在我的 pom.xml 中排除了它,然后添加了新的番石榴依賴
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.