maven: maven-shade-plugin

文章目录

一、介绍

  • 官网:https://maven.apache.org/plugins/maven-shade-plugin/
  • 功能:功能类似assembly,但支持依赖包的重命名(避免版本冲突)、配置文件的追加(避免覆盖)等,可用于制作fat-jar。
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                        <! --
							原始jar名称:xx.jar
							最终输出的jar名称:
								true: xx-shaded.jar
								false: xx.jar并修改原始jar名称为original-xx.jar
						 -->
                            <shadedArtifactAttached>false</shadedArtifactAttached>
                            <!-- 生成名为dependency-reduce-pom.xml,这个xml去掉了原始pom中已被包含进fat-jar的依赖项 -->
                            <createDependencyReducePom>true</createDependencyReducePom>
                            <!-- 类重定向 -->
                            <relocations>
                                <relocation>
                                <!-- 指定需要被重命名的包名 -->
                                    <pattern>net.</pattern>
                                    <!-- 指定重命名后的包名 -->
                                    <shadedPattern>xxx.xxx.net.</shadedPattern>
                                </relocation>
                            </relocations>

						    <transformers>
								<!-- 所有transformer:https://maven.apache.org/plugins/maven-shade-plugin/usage.html -->
								<!-- 等价于manifestEntries下的Main-Class -->
								<!-- 为MANIFEST.MF文件添加指定的key和value -->
								<manifestEntries>
									<Main-Class>com.xxx.xxx.Test</MainClass>
									<Build-Number>123</Build-Number>
							</manifestEntries>
							</transformer>

                            <!-- 指定要排除或包含的依赖 -->
                            <artifactSet>
                            <!-- 默认所有的依赖都会被解压后平铺到最终的fat-jar中,这里指定要排除哪些依赖,格式:groupId:artifactId[[:type]:classifier], 支持“*”和“?”通配符 -->
									<excludes>
										<exclude>*:hutool-all</exclude>
									</excludes>
							</artifactSet>
							<!-- 更细粒度的控制每个依赖;指定要排除或包含的内容 -->
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>java.**</exclude>
                                        <exclude>META-INF/**</exclude>
                                        <exclude>module-info.class</exclude>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.MF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>META-INF/LICENSE</exclude>
                                        <exclude>META-INF/NOTICE</exclude>
                                        <exclude>META-INF/DEPENDENCIES</exclude>
                                        <exclude>META-INF/*.txt</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

参考:

  • https://blog.csdn.net/h_bpdwn/article/details/133909695?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0-133909695-blog-80619481.235v43pc_blog_bottom_relevance_base7&spm=1001.2101.3001.4242.1&utm_relevant_index=3
  • https://www.bilibili.com/video/BV1ne411978x/?spm_id_from=333.1007.top_right_bar_window_history.content.click
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玉成226

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值