小编典典

NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.directExecutor在elasticsearchjar中发生冲突

elasticsearch

创建Elasticsearch
Client时,出现异常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>

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


阅读 393

收藏
2020-06-22

共1个答案

小编典典

您应该尝试查找番石榴的“旧”版本的来源,并将其全部排除一次。

查找依赖项:

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>

有关依赖性排除的更多信息,请参见https://maven.apache.org/guides/introduction/introduction-to-
optional-and-excludes-
dependencies.html。

2020-06-22