shade~实现打包多个关联包并过滤配置文件

使用maven-shade-plugin插件可以帮我们把多个依赖包打包一个jar包,并且在打包时可以帮我们过滤一些文件,比如每个依赖包里都有application.properties文件,在打包时这个文件会进行合并,这对于使用者来说是不希望的,它们更希望自己去写配置信息,所以在打包时,应该把配置文件过滤掉。

下面代码帮我们实现了关联包合并及过滤配置文件

<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>
                                    </excludes>
                                </filter>
                            </filters>
                            <artifactSet>
                                <!-- 捆绑包含-->
                                <includes>
                                    <include>com.lind:lind-common</include>
                                    <include>com.lind:lind-limit-start</include>
                                    <include>com.lind:lind-lock-start</include>
                                </includes>
                                <!-- 排除文件-->
                                <!-- <excludes>-->
                                <!-- </excludes>-->
                            </artifactSet>
                            <createSourcesJar>true</createSourcesJar>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

打完包之后,我们看到有源码jar和目标jar
1
我们任意打开一个jar,通过解压软件可以看到,里面的配置文件被过滤了
2

posted @ 2020-11-12 09:45  张占岭  阅读(795)  评论(0编辑  收藏  举报