maven-shade-plugin可以用來進行打包,並實現在打包過程中的一些過濾、排除、包含、重命名等一系列操作,當我們設計公用項目時,有時在項目時會有一些測試用例,如果在打包時想把這些測試包排除,使用maven-shade-plugin
插件是個不錯的選擇。
打包包含和排除
下面的代碼實現了以下幾個功能:
- 打包時排除com.lind.uaa.jwt.three包下的所有內容
- 打包時排除項目的properties類型的配置文件
- 打包時,com.baomidou組織的包添加到當然JAR包里,默認是不會添加到當前包的
createSourcesJar
選項實現了打包時為源代碼再打一個包
<build>
<plugins>
<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>
<!-- 過濾器排除配置文件-->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>com/lind/uaa/jwt/three/**</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<!-- 捆綁包含,目標項目不需要再手動引用這個包了 -->
<includes>
<include>com.baomidou:*</include>
</includes>
</artifactSet>
<createSourcesJar>true</createSourcesJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>