Applying MAVEN Shade Plugin To resolve multiple version conflicts with jars or classes Resolving multi-version conflicts with a jar or class using Maven shade plugin
Java applications often encounter the dependency of the three-party library version conflict, the following is a specific example.
Dubbo is a distributed service framework in which one of the RPC implementations (Dubbo protocol) uses Hessian 3.2. The other implementation (HSF protocol) also uses Hesssian, but the version used is 3.0.14. If the Dubbo protocol and the HSF protocol are used at the same time in an application, which version of Hessian does the application use at this time? Using 3.2.0 may affect the HSF agreement, and if you use 3.0.14 then the Dubbo protocol will be affected.
Maven Shade Plugin is able to package some of the class files in the jar packages that are dependent on the project into the jar package generated by the project build, and it has a very important feature to support relocation when packaging. Relocation means renaming a class, such as renaming Com.caucho.hessian.io.HessianInput to Hidden.com.caucho.hessian.io.HessianInput, so there will be no conflict.
The following is the configuration of the shade plugin in the project.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>mav En-shade-plugin</artifactid> <version>1.7.1</version> <executions> <execution> <id>s Hade-hessian</id> <goals> <goal>shade</goal> </goals> <configuration> <artifactset > <includes> <include>hessian:hessian< /include> </includes> </artifactSet> <createSourcesJar>true</createSourcesJar> <relocations> <relocation> <pattern>com.caucho</pattern> <shade Dpattern>com.alibaba.dubbo.hsf.hessian.v3_0_14_bugfix</shadedpattern> </relocat Ion> </relocations> </configuration> & Lt;/execution> </executions> </plugin>
The above configuration puts GroupId to Hessian Artifactid also for Hessian dependencies in Com.caucho package after all classes renamed to Com.alibaba.dubbo.hsf.hessian.v3_0_14_bugfix And the class files in the project are hit into the jar package.
Maven 2 is packaged this way, and you can look at the jar in the Lib directory under the Maven 2 installation directory.
Applying MAVEN Shade Plugin To resolve multiple version conflicts with jars or classes