问题描述
在创建 Elasticsearch 客户端时,我收到异常 java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;经过一番查找,Guava-18 之类的接缝在运行时被旧版本覆盖,而 Guava-18 仅在编译任务期间工作.
While creating Elasticsearch Client, I'm getting the exception java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; After some lookup, seams like the Guava-18 is being overwrite by an older version at runtime, and Guava-18 only works during compile task.
我的Maven配置如下:
My Maven configuration is the follow:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
如何在执行时强制使用 Guava-18 版本?
How can i force the Guava-18 version at execution time?
推荐答案
您应该尝试找出旧"版本番石榴的来源,并一劳永逸地排除它.
You should try to find where the "old" version of guava is taken from and to exclude it once for all.
找到依赖:
mvn 依赖:树 |grep番石榴
排除它:
<dependency>
<groupId>org.whatever</groupId>
<artifactId>the_lib_that_includes_guava</artifactId>
<version>0.97</version>
<exclusions>
<exclusion>
<artifactId>com.google</artifactId>
<groupId>guava</groupId>
</exclusion>
</exclusions>
</dependency>
见https://maven.apache.org/guides/Introduction/introduction-to-optional-and-excludes-dependencies.html 了解更多关于依赖项排除的信息.
See https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html for more info on the dependency exclusion.
这篇关于NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor 在 Elastic Search jar 上冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!