Nav

Shading Libraries

DevKit version 3.5.3 and later supports shading (renaming) .jar files using the Apache Maven Shade Plugin, by specifying the plugin in your project’s pom.xml file.

If needed, add the "shading" plugin dependency to your pom.xml file so that a .jar filename does not collide with another version of the library with the same name implemented by Mule.

Before considering using the shading plugin to use your custom .jar without collision with a different version or antecedent of the .jar, it is advisable to take one of these approaches before considering shading.

  • Use the same version of the library as Mule does

  • Use an entirely different library that doesn’t collide with one implemented by Mule

Add the Shade Plugin

  • Add the shading plugin to your connector’s pom.xml file.

  • Add the custom .jar to the connector by specifying it in the pom.xml file.

The following example shows org.some.library and an artifactId of custom-artifact-id as dependencies:


         
      
1
2
3
4
5
6
7
<dependencies>
   <dependency>
       <groupId>org.some.library</groupId>
       <artifactId>custom-artifact-id</artifactId>
       <version>2.0</version> <!-- version is in connector's JAR -->
   </dependency>
</dependencies>

Shade Plugin in Action

The following example shows the output after building the connector. The shading plugin takes care of renaming the artifact, which without the shading plugin, could have collided with another version of the artifact in Mule:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<build>
 <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-shade-plugin</artifactId>
     <version>2.3</version>
     <configuration>
       <!-- custom shade configuration -->
       <artifactSet>
         <includes>
            <include>org.some.library:custom-artifact-id</include>
         </includes>
       </artifactSet>
       <relocations>
         <relocation>
            <pattern>org.some.library</pattern>
            <shadedPattern>org.some.library.new.pakage.name.shade</shadedPattern>
         </relocation>
       </relocations>
      </configuration>
   </plugin>
  <!-- Other plugins -->
 </plugins>
</build>