创建 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 版本?
原文由 André Alves 发布,翻译遵循 CC BY-SA 4.0 许可协议
您应该尝试找到“旧”版本的番石榴的来源,并一劳永逸地排除它。
找到依赖项:
mvn dependency:tree | grep guava
排除它:
有关依赖项排除的更多信息,请参阅 https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html 。