情况是,我有两个结构相同的Maven多模块项目:
Parent - Module 1 - Module 2
当我构建项目 1 时,我看到先构建父级(顺序为 parent->module1->module2)。但是对于项目 2,最后构建父级(顺序为 module1->module2->parent)。为什么这两个项目有不同的构建顺序?另外,如何手动控制构建顺序?
更新 1:
两个父项目都是简单的POM项目,没有源代码,所以无法按照依赖图解释构建顺序。
更新 2:
除了 GAV 和子模块名称之外,父 POM 相同:
<?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>parent-group-id</groupId> <artifactId>parent-artifact-id</artifactId> <version>parent-version</version> <packaging>pom</packaging> <name>parent-name</name> <modules> <module>module-1</module> <module>module-2</module> </modules> </project>
最佳答案
构建顺序由 Maven react 器确定,这是一种通过对项目进行排序来自动确保多模块构建的正确构建顺序的机制。
见 the official documentation了解它的工作原理。
上面写着:
The following relationships are honoured when sorting projects:
- a project dependency on another module in the build
- a plugin declaration where the plugin is another modules in the build
- a plugin dependency on another module in the build
- a build extension declaration on another module in the build
- the order declared in the element (if no other rule applies)
您无法手动控制构建顺序。如果您想更改顺序,您必须对您的项目做出影响 react 堆排序顺序的更改。
关于java - Maven多模块项目的构建顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131575/