NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在Elastic Search jar上进行conflits

And*_*ves 15 java jar maven guava elasticsearch

在创建Elasticsearch客户端时,我得到异常java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; 在一些查找之后,像Guava-18这样的接口在运行时被旧版本覆盖,而Guava-18仅在编译任务期间工作.

我的Maven配置如下:

    <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>
Run Code Online (Sandbox Code Playgroud)

我如何在执行时强制使用Guava-18版本?

dev*_*arn 20

您应该尝试找到"老"版本的番石榴从哪里取出并一次性排除它.

找到依赖:

mvn dependency: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>
Run Code Online (Sandbox Code Playgroud)

有关依赖项排除的详细信息,请参阅https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html.

  • 请注意,给定的排除示例没有正确的组和工件ID.(groupId应为_com.google.guava_并示例artifactId _guava-jdk5_)复制粘贴事件:D (3认同)
  • 感谢您的回答,但我无法删除旧的番石榴版本,不属于我的代码。 (2认同)