本文介绍了NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor conflits on Elastic Search jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建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依赖:tree | grep guava

排除它:

<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>

请参阅了解更多关于依赖关系排除。

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 conflits on Elastic Search jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 21:36