Elasticsearch 5 Java client does not work with Groovy Grape


(Fabrizio Fortino) #1

Not sure this problem is caused by Elasticsearch or Groovy Grape.

I have a groovy script that uses Grape to handle dependencies:

@Grapes([
        @Grab(group = 'org.elasticsearch', module = 'elasticsearch', version = '5.0.0'),
        @Grab(group = 'org.elasticsearch.client', module = 'transport', version = '5.0.0'),
        @Grab(group = 'org.apache.logging.log4j', module = 'log4j-api', version = '2.7'),
        @Grab(group = 'org.apache.logging.log4j', module = 'log4j-core', version = '2.7')
])

Netty transitive dependencies coming from 'org.elasticsearch.client.transport' are not correctly included and when I try to connect I get the following ClassNotFoundException

Caught: java.lang.NoClassDefFoundError: io/netty/channel/RecvByteBufAllocator
java.lang.NoClassDefFoundError: io/netty/channel/RecvByteBufAllocator
        at org.elasticsearch.transport.Netty4Plugin.getSettings(Netty4Plugin.java:39)
        at org.elasticsearch.plugins.PluginsService.lambda$getPluginSettings$0(PluginsService.java:85)
        at org.elasticsearch.plugins.PluginsService.getPluginSettings(PluginsService.java:85)
        at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:115)
        at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:228)
        at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:69)
        at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:65)

Running 'grape resolve org.elasticsearch.client transport 5.0.0' returns

/Users/user/.groovy/grapes/org.elasticsearch.client/transport/jars/transport-5.0.0.jar
/Users/user/.groovy/grapes/org.elasticsearch/elasticsearch/jars/elasticsearch-5.0.0.jar
/Users/user/.groovy/grapes/org.apache.lucene/lucene-core/jars/lucene-core-6.2.0.jar
/Users/user/.groovy/grapes/org.elasticsearch/securesm/jars/securesm-1.1.jar
/Users/user/.groovy/grapes/net.sf.jopt-simple/jopt-simple/jars/jopt-simple-5.0.2.jar
/Users/user/.groovy/grapes/com.carrotsearch/hppc/jars/hppc-0.7.1.jar
/Users/user/.groovy/grapes/joda-time/joda-time/jars/joda-time-2.9.4.jar
/Users/user/.groovy/grapes/org.joda/joda-convert/jars/joda-convert-1.2.jar
/Users/user/.groovy/grapes/org.yaml/snakeyaml/bundles/snakeyaml-1.15.jar
/Users/user/.groovy/grapes/com.fasterxml.jackson.core/jackson-core/bundles/jackson-core-2.8.1.jar
/Users/user/.groovy/grapes/com.tdunning/t-digest/jars/t-digest-3.0.jar
/Users/user/.groovy/grapes/org.hdrhistogram/HdrHistogram/bundles/HdrHistogram-2.1.6.jar
/Users/user/.groovy/grapes/net.java.dev.jna/jna/jars/jna-4.2.2.jar
/Users/user/.groovy/grapes/org.elasticsearch.plugin/transport-netty3-client/jars/transport-netty3-client-5.0.0.jar
/Users/user/.groovy/grapes/io.netty/netty/bundles/netty-3.10.6.Final.jar
/Users/user/.groovy/grapes/org.elasticsearch.plugin/transport-netty4-client/jars/transport-netty4-client-5.0.0.jar
/Users/user/.groovy/grapes/io.netty/netty-common/jars/netty-common-4.1.5.Final.jar
/Users/user/.groovy/grapes/org.elasticsearch.plugin/reindex-client/jars/reindex-client-5.0.0.jar
/Users/user/.groovy/grapes/org.elasticsearch.client/rest/jars/rest-5.0.0.jar
/Users/user/.groovy/grapes/org.apache.httpcomponents/httpcore/jars/httpcore-4.4.5.jar
/Users/user/.groovy/grapes/commons-codec/commons-codec/jars/commons-codec-1.10.jar
/Users/user/.groovy/grapes/commons-logging/commons-logging/jars/commons-logging-1.1.3.jar
/Users/user/.groovy/grapes/org.elasticsearch.plugin/lang-mustache-client/jars/lang-mustache-client-5.0.0.jar
/Users/user/.groovy/grapes/com.github.spullara.mustache.java/compiler/jars/compiler-0.9.3.jar
/Users/user/.groovy/grapes/org.elasticsearch.plugin/percolator-client/jars/percolator-client-5.0.0.jar

I have also tried to include the netty dependency but it then complains about other missing ones (like lucene).
The same script with elasticsearch 2.4.x works well and the dependency are correctly resolved. Any idea?


(Yannick Welsch) #2

I'm not sure what the exact problem is. I just noticed that grape resolves some of the dependencies in a funky way depending on the mode used, e.g.:

$ grape resolve org.elasticsearch.plugin transport-netty4-client 5.0.0
/Users/ywelsch/.groovy/grapes/org.elasticsearch.plugin/transport-netty4-client/jars/transport-netty4-client-5.0.0.jar
/Users/ywelsch/.groovy/grapes/io.netty/netty-common/jars/netty-common-4.1.5.Final.jar
$ grape resolve -ant org.elasticsearch.plugin transport-netty4-client 5.0.0
<pathelement location="/Users/ywelsch/.groovy/grapes/org.elasticsearch.plugin/transport-netty4-client/jars/transport-netty4-client-5.0.0.jar">
<pathelement location="/Users/ywelsch/.groovy/grapes/io.netty/netty-common/jars/netty-common-4.1.5.Final.jar">
$ grape resolve -ivy org.elasticsearch.plugin transport-netty4-client 5.0.0
<dependency org="org.elasticsearch.plugin" name="transport-netty4-client" revision="5.0.0">
<dependency org="io.netty" name="netty-buffer" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-codec" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-codec-http" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-common" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-handler" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-resolver" revision="4.1.5.Final">
<dependency org="io.netty" name="netty-transport" revision="4.1.5.Final">

(Fabrizio Fortino) #3

Thanks for that!

It seems that grapes resolves OK when -ivy is passed as argument. I do think something has changed in version 5 since it was working fine in 2.4 .

Do you know if I can change the resolver to ivy in my groovy script? I have seen there is a GrabResolver but I am not sure is the right way to sort the problem out.

ty


(Yannick Welsch) #4

I've investigated further and opened


(Jason Tedor) #5

Side note: the version of the Log4j dependency for 5.0.0 should be 2.6.2, not 2.7 as you have here. Otherwise you will see NoClassDefFoundError for org.apache.logging.log4j.core.async.DaemonThreadFactory.


(Fabrizio Fortino) #6

Solved with ES 5.0.1


(system) #7