简化了一下方便自己记录
单继承的两种方式
方式一:
1、父模块 account-aggregator
只显示主要部分 pom.xml
<groupId>com.youzhibing.account</groupId>
<artifactId>account-aggregator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Account Aggrregator</name>
<modules>
<!-- 子模块都写在此处 -->
<module>account-register</module>
</modules>
<!-- 配置共有依赖 -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
</dependencies>
</project>
2、子模块account-register
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.youzhibing.account</groupId>
<artifactId>account-aggregator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- 与不配置一样,默认就是寻找上级目录下得pom.xml -->
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>account-register</artifactId>
<name>account-register</name>
<!-- 配置自己独有依赖 -->
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.3</version>
</dependency>
</dependencies>
方式二:配置dependencyManagement
1、父模块 account-aggregator
只显示主要部分 pom.xml
<groupId>com.youzhibing.account</groupId>
<artifactId>account-aggregator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Account Aggrregator</name>
<modules>
<!-- 子模块都写在此处 -->
<module>account-register</module>
</modules>
<!-- 配置共有依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2、子模块account-register
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.youzhibing.account</groupId>
<artifactId>account-aggregator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- 与不配置一样,默认就是寻找上级目录下得pom.xml -->
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>account-register</artifactId>
<name>account-register</name>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
父POM使用dependencyManagement能够统一项目范围中依赖的版本,当依赖版本在父POM中声明后,子模块在使用依赖的时候就无须声明版本,也就不会发生多个子模块使用版本不一致的情况,帮助降低依赖冲突的几率。如果子模块不声明依赖的使用,即使该依赖在父POM中的dependencyManagement中声明了,也不会产生任何效果
多继承
1、父模块 maven-father
只显示主要部分 pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.cbm.stu</groupId>
<artifactId>maven-father</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>maven-father</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
2、父模块 maven-monther
<modelVersion>4.0.0</modelVersion>
<groupId>com.cbm.stu</groupId>
<artifactId>maven-monther</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>maven-monther</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
</dependencies>
</dependencyManagement>
3、子模块 maven-child
只显示主要部分 pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.cbm.stu</groupId>
<artifactId>maven-parent-a</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>maven-parent-b</name>
<dependencyManagement>
<dependencies>
<!-- 此处继承了father 和 monther 两个项目,type为pom,scope 为 import -->
<dependency>
<groupId>com.cbm.stu</groupId>
<artifactId>maven-father</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.cbm.stu</groupId>
<artifactId>maven-monther</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 从继承的父项目中继承依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
</dependencies>