Maven集合和继承

Maven聚合和继承

一. 聚合

1. 聚合的目的:一次构建多个模块和项目。

2. 聚合的packaging为POM,聚合下的module的值都是一个当前POM的相对目录。

3. 对于聚合模块来说,它知道哪些被聚合的模块,但是那些被聚合的模块并不知道聚合模块的存在。

聚合的例子如下:

<groupId>com.account</groupId>

<artifactId>accout-aggregator</artifactId>

<packaging>pom</packaging>

<name>testName</name>

<modules>

    <module>module1</module>

    <module>module2</module>

</modules>

 

 

二. 继承

1. 继承的目的: 减少重复,重用一些公用的配置,如依赖,版本号,plugin 等等。

2. 继承的pom的packaging类型也为pom。

3. 在子pom中引用parent,其中groupId,artifactId 和version是必须的

   

<parent>
   <groupId>parent groupid</groupId>
   <artifactId>parent artifactid</artifactId>
   <version>parent version</version>
   <relativePath>parent pom path</relativePath>
</parent>

 4. 对于继承的父pom来说,它不知道有哪些子模块继承于它,但是那些子模块都必须知道自己的父pom是什么。