2

I trying to use Maven Shade and wrap ElasticSearch jar.

The reason, why I doing it is because I have a conflict between Lucene version in my project.

But I found problem, when I using Shade. It doesn't change name of file in META-INF/services and also doesn't change FQN in that particular files.

I need to change org.apache.lucene.codecs.Codec file and its content. Because if this file keep its name, then I get error
"Caused by: java.lang.IllegalArgumentException: An SPI class of type shaded_lucene_4_10_4.org.apache.lucene.codecs.Codec with name 'Lucene410' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classpath supports the following names: []"

Is it possible to wrap up ElasticSearch with Maven Shade plugin?

Here is my pom.xml

P1kachu
  • 1,077
  • 3
  • 11
  • 33
MicTech
  • 42,457
  • 14
  • 62
  • 79

1 Answers1

3

Yes it is possible, just need to add a ServicesResourceTransformer entry. Like this:

  <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.ManifestResourceTransformer">
              <mainClass>org.myorg.esclient.App</mainClass>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>

Check: http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer

Oldsong
  • 31
  • 3
  • I don't think the ServicesResourceTransformer renames the service files, it only renamed the classnames inside the files. This fails for Lucene. There's some bugs files for this, but it looks like it's only being included in the 3.0.0 version of the maven shade plugin. See https://issues.apache.org/jira/browse/MSHADE-221 – Thor Nov 22 '16 at 14:36