Maven 的聚合(多模块)和 Parent 继承
即使是长期从事Maven工作的开发人员也不能完全掌握聚合(多模块)和Parent继承的关系,在使用多模块时,子模块总要指定聚合的pom为 <parent>。由于在大多数示例中都是这么写的,所以很难让人搞懂这两者的具体作用和关系。实际上在Maven中聚合(多模块)和继承是两回事,两者不存在直接联系。pom文档地址:https://maven.apache.org/pom.htm
即使是长期从事 Maven 工作的开发人员也不能完全掌握聚合(多模块)和 Parent 继承的关系,在使用多模块时,子模块总要指定聚合的 pom 为 <parent>。由于在大多数示例中都是这么写的,所以很难让人搞懂这两者的具体作用和关系。
实际上在 Maven 中聚合(多模块)和继承是两回事,两者不存在直接联系。
pom文档地址:https://maven.apache.org/pom.html
Maven 完全参考:http://books.sonatype.com/mvnref-book/reference/index.html
继承
继承是 Maven 中很强大的一种功能,继承可以使得子POM可以获得 parent 中的各项配置,可以对子pom进行统一的配置和依赖管理。父POM中的大多数元素都能被子POM继承,这些元素包含:
groupId
version
description
url
inceptionYear
organization
licenses
developers
contributors
mailingLists
scm
issueManagement
ciManagement
properties
dependencyManagement
dependencies
repositories
pluginRepositories
build
plugin executions with matching ids
plugin configuration
etc.
reporting
profiles
注意下面的元素,这些都是不能被继承的。
artifactId
name
prerequisites
想要添加 parent,只需要像下面这样写
原创不易,完成人机校验,阅读全文