类的依赖冲突通常有两种方式:
1.当冲突两者其中一方兼容另外一方时,通过exclusions和exclusion标签解决。
2.但也有时我们需要两个包同时兼容,那么可以通过以下插件来解决,创建一个空项目,将其中一个依赖打进项目,然后通过relocation将包名更改为新包名,重新打包封装出新包引用.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<relocations>
<!-- 多个包需要替换使用多个relocation-->
<relocation>
<!-- pattern 为需要匹配的前缀-->
<pattern>org.slf4j</pattern>
<!-- shadedPattern 为替换成什么前缀-->
<shadedPattern>ceshi.org.slf4j</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>