文章目录
- maven-assembly-plugin
Assembly 插件支持将项目的所有依赖、文件都打包到同一个输出文件中
基本使用
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.xxx</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
会生成两个包 后缀为 jar-with-dependencies 是含有第三方依赖的 JAR 包 也就是胖包 后缀没有的是瘦包 没有任何依赖瘦包
- maven-shade-plugin
maven-shade-plugin 比 maven-assembly-plugin 功能更为强大,比如你的工程依赖很多的 JAR 包,而被依赖的 JAR 又会依赖其他的 JAR 包,这样,当工程中依赖到不同的版本的 JAR 时,并且 JAR 中具有相同名称的资源文件时,shade 插件会尝试将所有资源文件打包在一起时,而不是和 assembly 一样执行覆盖操作。通常使用 maven-shade-plugin 就能够完成大多数的打包需求,其配置简单且适用性最广,因此建议优先使用此方式。
基本使用
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<!-- 禁止生成 dependency-reduced-pom.xml-->
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<!-- Run shade goal on package phase -->