这篇文章主要介绍Maven项目继承实现过程的案例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

多个maven项目之间难免有重复的pom配置,重复的配置没必要重复写,maven提供了父子继承的关系,重复的依赖直接放在父项目的pom中。
所以不希望每个开发者随意定义maven版本依赖,可以在父项目中进行说明,然后子项目沿用即可。
idea创建父项目(这是一个父项目,也是一个空项目,只需要pom.xml,编写相关的依赖, 父项目必须用pom打包的方式):

编辑父项目pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.linewell</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<!--父项目必须是pom-->
<packaging>pom</packaging>
<!--定义参数-->
<properties>
<common.version>2.6</common.version>
<spring.version>4.3.6.RELEASE</spring.version>
</properties>
<!--这边的依赖子项目会继承-->
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${common.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>spring-context-support</groupId>
<artifactId>org.springframework</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>