Applying MAVEN Shade Plugin To resolve multiple version conflicts with jars or classes

Source: Internet
Author: User
Tags maven shade plugin

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.