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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With