java - Maven多模块项目的构建顺序?

标签 java maven build multi-module

情况是,我有两个结构相同的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/

相关文章:

java - 从其他线程访问 View (Android)

java - 大 table 斯普林鲁

java - 没有 OutOfMemory 异常的内存泄漏?

java - Buildozer 不适用于 cygwin 下的 java

Ubuntu boost b2 错误 : Cannot use --layout=system with --build-type complete

java - 这两本书哪个更适合学习Java线程?

java - 如果我还想发布 alpha、beta 和 rc,那么在开发过程中,我应该在 Maven 项目中使用哪个版本?

java - 如何在Android SDK(在Travis中)上获取tools/source.properties?

spring - 如何将依赖项上载到 Artifact 服务器

java - Jenkins maven无法在JDK中找到Javac编译器