Java – Why doesn’t relocation with the maven shade plugin work?

Why doesn’t relocation with the maven shade plugin work?… here is a solution to the problem.

Why doesn’t relocation with the maven shade plugin work?

I have some trouble running Hadoop jobs containing more than the Hadoop release (CDH 5.2) The version included in the updated Guava version. This is a known issue. I tried to solve itby shading the libraries Use the Maven shadow plugin. So I add 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, shadows don’t seem to work. When I extract uber-jar, there is no folder thirdparty/com/google but still folder com/google.

Does anyone know what went wrong?

Solution

This worked for me :

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

Notice the dot at the end of the pattern.

Related Problems and Solutions