maven-shade-plugin~打包时过滤项目中某些包

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>
posted @ 2020-12-13 19:11  张占岭  阅读(3695)  评论(0编辑  收藏  举报