继承
①现状
Hello依赖的junit: 4.0
HelloFriend依赖的junit:4.0
MakeFriends依赖的junit:4.9
由于test范围的依赖不能传递,所以必然会分散在各个模块工程,很容易造成版本不一样。
②需求:统一管理各个模块工程中对junit依赖的版本
③解决思路:将junit依赖版本统一提取到“父”工程中,在子工程中声明依赖时不指定版本。以父工程中统一设定的为准。同时也便于修改。
④操作步骤
【1】创建一个Maven工程作为父工程。注意:打包的方式pom
<groupId>com.atguigu.maven</groupId>
<artifactId>Parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
【2】在子工程中声明对父工程的引用
<parent>
<groupId>com.atguigu.maven</groupId>
<artifactId>Parent</artifactId>
<version>1.0-SNAPSHOT</version>
<!--以当前文件为基准的父工程pom.xml文件的相对路径-->
<relativePath>../../IDEATest/MyParents/pom.xml</relativePath>
</parent>
【3】将子工程的坐标中与父工程坐标中重复的内容删除
【4】在父工程中统一管理 junit的依赖
<!--统一配置依赖的管理-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
【5】在子工程中删除junit依赖的版本号部分
⑤注意:配置继承后,执行安装命令时要先安装父工程
聚合
①作用:一键安装各个模块工程。
②配置方式:在一个“总的聚合工程”中配置各个参与聚合的模块
<!--配置聚合-->
<modules>
<!--指定各个子工程的相对路径-->
<module>../../maven_test/Hello</module>
<module>../../maven_test/HelloFriend</module>
<module>../MakeFriends</module>
</modules>
③使用方式:在聚合工程的pom.xml中 maven install即可
查找jar包坐标信息的网站:https://www.mvnrepository.com