Maven的pom.xml文件结构之基本配置parent和继承结构

1.Maven项目的继承

Maven项目之间不仅存在多模块的聚合关系,而且Maven项目之间还可以存在相互继承的关系。

Maven项目之间的继承关系通过<parent>表示,在子Maven项目的POM中配置示例如下:

<parent>
    <groupId>com.mycompany.cat</groupId>
    <artifactId>cat-bundle</artifactId>
    <version>2.0</version>
    <relativePath>../cat-bundle</relativePath>
  </parent>

说明:给出被继承的父项目的具体信息。

其中的relativePath给出父项目相对于子项目的路径,这样在构件子项目时首先从该相对路径查找父项目,如果没有才会从本地库或进而远程库中查找父项目。

2.在子项目中,能够继承父项目的如下配置:

    dependencies developers contributors plugin lists reports lists plugin executions with matching ids plugin configuration

3.Maven的Super POM

类似于Java中的java.lang.Object类,所有Java类都继承自该类。在Maven中也存在一个特殊的POM,被称为Super POM。任何Maven项目的POM都继承自Super POM。

在Super POM中,设置如下:

    Maven的central库 Maven的central插件库 build的基本参数和4个插件(maven-antrun-plugin、maven-assembly-plugin、maven-dependency-plugin和maven-release-plugin) reporting的基本目录 一个profile(id=release-profile)
经验分享 程序员 微信小程序 职场和发展