maven 继承的方式有两种
1. 通过
<parent>
<groupId>com.thomas.yang</groupId>
<artifactId>School</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../School/pom.xml</relativePath>
</parent>
这种方式,引用父工程中信息,如果父工程中,有dependencies 不在dependencyManagement 内,通过
parent 的方式会直接导入导入到子工程,子工程不需要在声明这个引用
dependencyManagement内中的引用,子类想用使用,必须要在子工程的pom文件中的有dependencies中声明
引用父类中的那个依赖,不声明,不会引用;
2. 子类通过dependencyManagement 中scope = Import 标签来声明导入那个工程,可以实现多继承;
子类pom
<!--通过这个标签可以继承其他类型的工程,从而实现多继承-->
<dependencyManagement>
<dependencies>
<!-- 此处继承了School 和 School_B 两个项目,type为pom,scope 为 import -->
<dependency>
<groupId>com.thomas.yang</groupId>
<artifactId>School</artifactId>
<version>1.0-SNAPSHOT</version>
<!--声明依赖类型只能是pom -->
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.thomas.yang</groupId>
<artifactId>School_B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
子类虽然在dependencyManagement 中声明了导入依赖,但是导入的依赖的pom文件中可能会有很多其他
依赖,所以子类中需要用哪些依赖必须在dependencies 中声明如下:
<dependencies>
<!-- 从继承的父项目中继承依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
综上两种,引用的相同点,是必须在子工程中声明,需要引用哪些依赖
不同点parent的方式 可以直接依赖到父工程 公共的依赖,不需要在子工程中声明
dependencyManagement 不能直接依赖到父工程 公共的依赖;