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

850 阅读1分钟

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>

只要一步一个脚印,水滴石穿,吃透、搞懂、拿捏住是完全没有问题的!看到这里的都是妥妥的铁粉无疑了,底下是微信,找到的可是有大把源码,学习路线思维导图啥的,多的我就不透露,539413949看大家自己的积极性了啊,热爱所热爱的,学习伴随终生