MAVEN项目继承
对于一个pom.xml来说有几个元素是必须定义的,一个是project根元素,然后就是它里面的modelVersion、groupId、artifactId和version
parent
说明:给出被继承的父项目的具体信息。
其中的relativePath给出父项目相对于子项目的路径,这样在构件子项目时首先从该相对路径查找父项目,如果没有才会从本地库或进而远程库中查找父项目。
在本地库中查到
<parent>
<groupId>com.tiantian.mavenTest</groupId>
<artifactId>projectA</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../projectA/pom.xml</relativePath>
</parent>
说明:比如B项目引入A项目的maven配置(上面的代码写在B项目的配置中,relativePath根据具体位置调整)
本地库中查不到
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/>
</parent>
说明:org.springframework.boot是springboot的一个配置,本地找不到,这会引入服务器上的org.springframework.boot对应的maven配置
dependencyManagement
<properties>
<target.version>2.5.6</target.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>a_groupId</groupId>
<artifactId>a_artifactId</artifactId>
<version>${target.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>a_groupId</groupId>
<artifactId>a_artifactId</artifactId>
</dependency>
<!--或-->
<dependency>
<groupId>a_groupId.xx</groupId>
<artifactId>xx_artifactId</artifactId>
</dependency>
dependencyManagement下的dependencies与dependencies是有区别的,dependencyManagement下的dependencies,是配置了可继承,并不会引入对应的jar,dependencies会引入对应的jar, 所以我们在下面不写
version了,因为继承了version的值
参考内容http://blog.csdn.net/wanghantong/article/details/36427411
http://elim.iteye.com/blog/2055745