Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does relocation with the maven shade plugin not work?

I am having some trouble running a Hadoop job that includes a newer version of Guava than the one that is included in the Hadoop distribution (CDH 5.2). This is a known problem. I try to solve it by shading the libraries using the Maven shade plugin. Therefore, I added the following lines to my pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <relocations>
            <relocation>
              <pattern>com.google</pattern>
              <shadedPattern>thirdparty.com.google</shadedPattern>
            </relocation>
          </relocations>
        </configuration>
      </execution>
    </executions>
  </plugin>

Unfortunately, the shading seems not to work. When I extract the uber-JAR there is no folder thirdparty/com/google but still the folder com/google.

Does someone have an idea what is going wrong?

like image 664
Robert Avatar asked Dec 17 '14 22:12

Robert


People also ask

What is relocation in Maven?

Sometimes it is necessary to relocate artifacts in the repository. One example of that is when a project moves from one groupId to a different groupId. Making changes to the repository can have far reaching consequences. So it is best to get it right the first time, hence this guide.

Why is Maven Shade plugin used?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

What is shading in Maven?

Shading is performed by the Apache Maven Shade plugin. Shading = Relocation of the class to avoid a JAR hell. Shading i.e. rename - the packages of some of the dependencies.


1 Answers

This worked for me:

<relocations>
   <relocation>
     <pattern>com.google.</pattern>
     <shadedPattern>thirdparty.com.google.</shadedPattern>
   </relocation>
 </relocations>

note the dot at the end of the pattern.

like image 173
wcolen Avatar answered Sep 18 '22 20:09

wcolen