maven 多模块合并打包

使用 maven-shade-plugin 插件实现多模块项目开发,合并 class 打包成一个jar 包

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-shade-plugin</artifactId>
     <executions>
         <execution>
             <phase>package</phase>
             <goals>
                 <goal>shade</goal>
             </goals>
             <configuration>
                 <createSourcesJar>true</createSourcesJar>
                 <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                 <!-- 包含要合并的模块 -->
                 <artifactSet>
                     <includes>
                         <include>oo.xxx:xxx-xxxxx-core/include>
                         <include>oo.xxx:xxx-xxxxx-common/include>
                         <include>oo.xxx:xxx-xxxxx-config/include>
                     </includes>
                 </artifactSet>
                 <!-- 包含号合并的资源文件 -->
                 <transformers>
                     <transformer
                             implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                              <resource>META-INF/xxxxx
                         </resource>
                     </transformer>
                 </transformers>

             </configuration>
         </execution>
     </executions>
 </plugin>
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我理解了你的问题。针对 Maven模块合并打包,可以按照以下步骤进行操作: 1. 创建 Maven模块项目,将需要合并打包模块作为子模块引入到父模块中。 2. 在父模块的 pom.xml 文件中,使用 maven-assembly-plugin 插件配置合并打包的规则。例如: ``` <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <finalName>merged-jar</finalName> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> ``` 其中,finalName 表示打包后的文件名,appendAssemblyId 表示不使用默认的 assemblyId,descriptors 表示使用 assembly.xml 文件定义打包规则。 3. 在父模块中创建 assembly.xml 文件,定义打包规则。例如: ``` <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd"> <id>jar-with-dependencies</id> <formats> <format>jar</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <useProjectArtifact>false</useProjectArtifact> <useTransitiveDependencies>true</useTransitiveDependencies> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly> ``` 其中,id 表示打包规则的名称,formats 表示打包的格式,dependencySets 表示依赖的配置。这里的配置表示将所有运行时依赖打包到根目录下。 4. 执行 Maven 打包命令,例如: ``` mvn clean package ``` 5. 在父模块的 target 目录下,会生成一个 merged-jar.jar 的文件,包含了所有的子模块依赖。 至此,你就可以成功地实现了 Maven模块合并打包的操作。希望这个回答能够对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值