- 为什么使用聚合?
将项目的多个工程拆分为多个模块后,在构建这个项目的时候,需要手动逐个按模块进行构建。而使用了聚合之后,就可以不需要深入每个module去单独构建,而只需要在聚合项目下的pom.xml构建,就会完成对所有module的构建
<modules>
<module>../Hello</module>
<module>../HelloFriend</module>
<module>../MakeFriends</module>
</modules>
- 为什么使用继承机制?
使用继承机制是为了将依赖信息统一提取到父工程模块中进行统一管理。
– 创建父工程:创建父工程和创建一般的 Java 工程操作一致,唯一需要注意的是:打包方式处要设置为 pom
– 在子工程中引用父工程
<parent>
<groupId>com.atguigu.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
– 在父工程中管理依赖,在子项目中需要引入所需要的依赖,无需指定范围和版本号(由父工程中<dependencyManagement>指定),<dependencyManagement>同时管理父、子工程的依赖版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>