Maven Multi Module
验证:未记录
- 适用版本
- 未记录
- 验证范围
- 尚未登记验证记录。
本文缩写(英文全称与中文含义)
| 缩写 | 英文全称/名称 | 中文含义 |
|---|---|---|
| POM | Project Object Model | Maven 项目对象模型 |
Links#
https://maven.apache.org/guides/mini/guide-multiple-modules.html
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html1. Important Points#
aggregator:
root POM lists modules and controls reactor build order
parent:
inherited POM that centralizes versions and plugin config
one POM can be both aggregator and parent.2. Layout#
order-platform
├── pom.xml
├── order-api
│ └── pom.xml
├── order-service
│ └── pom.xml
└── order-client
└── pom.xml3. Root POM#
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>order-platform</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>order-api</module>
<module>order-service</module>
<module>order-client</module>
</modules>
<properties>
<java.version>21</java.version>
</properties>
</project>4. Child POM#
<parent>
<groupId>com.example</groupId>
<artifactId>order-platform</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>order-service</artifactId>5. Reactor Commands#
./mvnw clean verify
./mvnw -pl order-api test
./mvnw -pl order-api -am test
./mvnw -pl order-api -amd test-pl:
selected projects
-am:
also make required dependencies
-amd:
also make dependents6. Internal Dependency#
<dependency>
<groupId>com.example</groupId>
<artifactId>order-service</artifactId>
<version>${project.version}</version>
</dependency>7. Plugin Rule#
library module 不应重打包成 Spring Boot executable jar;仅应用入口模块启用对应 repackage。
root parent:
put versions in pluginManagement
application module:
enable spring-boot-maven-plugin
library module:
do not repackage as executable jar8. Common Mistakes#
root POM package is not pom:
modules will not work correctly
plugin runs in every module:
check inherited flag and plugin placement
module cannot resolve sibling:
build from root or use -am