12

I have a Maven parent project which has multiple child/modules...I have the following pom.xml for the main/parent;

<modules>
        <module>Main-Ear</module>
        <module>Sub-Web</module>
        <module>Sub-Ui</module>
        <module>Sub-Services</module>
        <module>Sub-SSO-Login</module>
  </modules>

However, I find the actual build order to be different... After build, the actual order looks like;

Main
Sub-Services
Sub-SSO-Login
Sub-UI
Sub-Web
Main-Ear

Where exactly does Maven take the build order from in this case?

copenndthagen
  • 49,230
  • 102
  • 290
  • 442

2 Answers2

12

You can't manually control the build order:

From Maven project documentation (Guide to Working with Multiple Modules):

Reactor Sorting

Because modules within a multi-module build can depend on each other, it is important that The reactor sorts all the projects in a way that guarantees any project is built before it is required.

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)

Note that only "instantiated" references are used - dependencyManagement and pluginManagement elements will not cause a change to the reactor sort order

Roland Tepp
  • 8,301
  • 11
  • 55
  • 73
Sambuca
  • 1,224
  • 18
  • 30
5

Maven not taken the module building order from what we define in the main pom.xml. Maven decide the order by considering module dependencies with each other modules.

In your case definitely Main-Ear should build last.

Let's consider following example.

I have module A, B and C. Module A has dependency from module C and B while module C has dependency from module B. Then maven building order will be

B
C
A  
Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115
  • 1
    So, u are saying there would be no explicit declaration anywhere in pom.xml...but Maven takes the decision on it's own..based on dependencies.... – copenndthagen Sep 05 '13 at 07:13
  • @testndtv Yes. I think (but I am not sure) it may still depends on the order you declare, if two sub-modules has no dependencies between them. e.g. A -> C and B -> C, then Maven may use order of declaration to determine which of A or B is built first – Adrian Shum Sep 05 '13 at 07:17
  • 1
    @AdrianShum If there is no dependencies between each other, then maven will use what ever order we define – Ruchira Gayan Ranaweera Sep 05 '13 at 07:19