Maven 聚合

应用场景:假设现有项目 helloMvn,该项目有2个模块,helloMvnService 和 helloMvnPersist

需求:运行一次mvn命令,同时构建两个模块 。

解决办法:利用mvn的聚合特性。

操作:

1.新建项目helloMvnAggregator,该项目仅仅需要包含pom.xml 就可以 ,helloMvnAggregatorhelloMvnService 、helloMvnPersist在同一个平行目录,假设项目路径为

helloMvn

                 --helloMvnService 

                 --helloMvnPersist

                 --helloMvnAggregator

2.编写pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.helloMvn</groupId>
<artifactId>helloMvnAggregator</artifactId>
<version>0.0.1-SNAPSHOT</version>

       <packaging>pom</packaging>

       <name>HelloMvn Aggregator</name>
  <modules>
  <module>../HelloMvnService</module>
  <module>../HelloMvnPersist</module>
  </modules>
</project>

需要注意的关键点:

1.packaging 一定要选择pom(,如不写该标签,默认是jar ),否则无法聚合。

2.添加新标签 module,module内容是被聚合模块pom.xml 的相对地址 ,以上配置中../是指当前目录的上一层目录,即

HelloMvnService项目相对helloMvnAggregator项目的pom地址为 helloMvn/HelloMvnService/pom.xml

3.通常聚合模块会被放在模块的最顶层,被聚合的模块做为子目录存在,这样用户得到源代码时,第一眼就能发现聚合模块的pom,从而省去了寻找聚合模块pom的时间,同时项目路径也更加清晰 ,所以以上module配置应改为: 

  <modules>
  <module>HelloMvnService</module>
  <module>HelloMvnPersist</module>  
  </modules>

则,目录为:

helloMvn

              --helloMvnAggregator

                                                  --helloMvnPersist

                                                   --helloMvnService

  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值