NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor conflits on Elastic Search jar

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

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.

My Maven configuration is the follow:

    maven-compiler-plugin3.01.71.7org.apache.maven.pluginsmaven-shade-plugin2.4.1packageshade

How can i force the Guava-18 version at execution time?

回答1:

You should try to find where the "old" version of guava is taken from and to exclude it once for all.

Find the dependency :

mvn dependency:tree | grep guava

Exclude it :

org.whateverthe_lib_that_includes_guava0.97com.googleguava

See https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html for more info on the dependency exclusion.



回答2:

I add the correct dependency of elasticsearch resolve the problem

com.google.guavaguava18.0


回答3:

Add a dependencyManagement block solves this problem:

com.google.guavaguava20.0

Reference:

http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/



回答4:

I had a similar problem. I created a .jar file (Java source), then I wanted to load that file into the Spark Shell. It turns out that Spark Shell loads jars from something similar to this spark-[version]-bin-hadoop[version]/jars/".

That directory had an older version of the guava which causes the error. I had the correct version in my pom.xml. I even added exclusions and all suggested responses. In conclusion, it is indeed a wrong version of guava. I copied the version that matches my pom.xml file. Hope this helps. Regards.



回答5:

SOLVED: I updated the Guava dependency to latest version and it solved the

  com.google.guavaguavalatest


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!