1、继承
①现状:C依赖B,B依赖A
A工程依赖junit :4.0
B工程依赖junit :4.0
C工程依赖junit :4.9
由于junit是test范围的依赖,不能传递,所以必然会分散在各个模块工程中。
②需求:统一管理各个模块工程中对应的junit版本
③解决思路:将junit依赖版本统一提取到“父”工程中,在子工程中声明junit依赖
时不指定版本。
④操作步骤
①)创建一个Maven工程作为父工程。注意:打包的方式为pom
②)在子工程中声明对父工程的引用,如下:
<parent>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<relativePath></relativePath>
</parent>
③)将子工程坐标中与父工程坐标中重复的内容删除
④)在父工程中统一声明junit依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<scope></scope>
</dependency>
</dependencies>
</dependencyManagement>
⑤)在子工程中删除junit依赖的版本号
⑥)注意:配置继承后,执行安装命令时要先安装父工程。
2、聚合
1)作用:一键安装各个模块工程
2)配置方式:(指定各子工程的相对路径)
<modules>
<module>../hello</module>
<module>../hellofriends</module>
</modules>
3)使用方式:在聚合工程的pom.xml上右键点击---run as -- maven installl
3、自动化部署(pom.xml配置)
<!-- 配置当前工程构建过程中的特殊设置 -->
<build>
<finalName>testWeb</finalName>
<!-- 配置构建过程中需要使用的插件 -->
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<
<configuration>
<container>
<containerId>tomcat6x</containerId>
<home>D:\test\apache-tomcat-6.0.39</home>
</container>
</configuration>
</plugin>
</plugins>
</build>
4、查找依赖信息的网站
http://mvnrepository.com/