Build order of Maven multimodule project?

The situation is, I have two Maven multimodule projects with the same structure:

Parent
    - Module 1
    - Module 2

When I build project 1, I see that parent is built first (order is parent->module1->module2 ). However for project 2, parent is built at last (order is module1->module2->parent ). Why are the two projects have different build orders? Furthermore, how can I manually control the build order?

Update 1:
Both parent projects are simple POM projects without source code, so I can't explain the build order as per the dependency graph.

Update 2:
The parent POMs are the same except the GAV and child module names:

<?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>

The build order is determined by the Maven reactor which is a mechanism that automatically ensures correct build order for multimodule builds by sorting the projects.

See the official documentation for how it works.

It says:

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)
  • You can't manually control the build order. If you want to change the order you have to make changes to your project that influence the reactor sort order.


    At a high level, the build order is based on a topological sort of the module dependency graph.

    EDIT: Question for you. I understand that project 1 contains two modules and so does project 2. But do the modules in project 2 explicitly declare the "parent" pom as a parent? I'm thinking that perhaps your project 1 modules explicitly declare the parent pom, and the project 2 modules don't. Which would mean that the project 2 "parent" isn't really a parent at all and therefore doesn't have to be built before the modules. That's my guess anyway.

    链接地址: http://www.djcxy.com/p/29684.html

    上一篇: maven构建依赖关系jar文件没有反映代码中的变化

    下一篇: 构建Maven多模块项目的顺序?