maven pom 聚合项目功能
maven pom 聚合项目功能
简介
在maven pom的官方文档中聚合的概念是:Project Aggregation is similar to Project Inheritance. But instead of specifying the parent POM from the module, it specifies the modules from the parent POM. By doing so, the parent project now knows its modules, and if a Maven command is invoked against the parent project, that Maven command will then be executed to the parent’s modules as well.
谷歌翻译:项目聚合类似于项目继承。但是它不是从模块中指定父 POM,而是从父 POM 中指定模块。通过这样做,父项目现在知道它的模块,并且如果针对父项目调用了 Maven 命令,那么该 Maven 命令也将被执行到父的模块。
从聚合项目的概念上看,聚合项目是在pom中指定子模块,且作用与该pom上的maven命令将同等作用于子模块.
也就是通过一个pom发现**其他子模块(子pom)**的功能,然后进行统一的构建,清理,打包等.属于降低工程复杂度使其便于管理的功能.
使用方法(例子来自于官方文档)
该功能在使用时必须进行以下两个操作
1.将父 POM 中的packaging标签更改为值“pom”。
2.在父 POM 中指定其模块(子 POM)的目录(相对路径)。
以下为修改后的父pom
当父pom在子pom的上一级文件夹时,module标签中可以直接填写子模块的artifactId
文件相对关系
.
|-- my-module
| `-- pom.xml
`-- pom.xml
对应的父pom修改方式
<project>
<modelVersion>4.0.0</modelVersion