Java – Build order of Maven multimodule project


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

    - 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="" xmlns:xsi="" xsi:schemaLocation="">

Best Solution

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.