因最近项目中有个需求需要开发一款公共服务,通过pom引入,注解引入到三方服务。公共服务中使用了poi,考虑到现在很多服务都包含poi为了避免依赖冲突问题使用maven-shade-plugin进行打包。对poi包名进行修改。
完成配置如下
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-maven-plugin -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<!--没有使用的依赖自动移除-->
<!--<minimizeJar>true</minimizeJar>-->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!--打包时需要被排除的文件,避免三方服务引用出现冲突 打包启动时不可排除 start-->
<!-- <exclude>**/*.yml</exclude>
<exclude>org/springframework/**</exclude>
<exclude>org/slf4j/**</exclude>-->
<!--打包时需要被排除的文件,避免三方服务引用出现冲突 打包启动时不可排除 end-->
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
<relocation>
<!--包名修改-->
<pattern>org.apache.poi</pattern>
<shadedPattern>shaded.org.poi</shadedPattern>
</relocation>
</relocations>
<transformers>
<!--处理多个jar包中存在重名的配置文件的合并-->
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>