Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven build order (Multiple modules) [duplicate]

Tags:

java

maven

build

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?

like image 484
copenndthagen Avatar asked Sep 05 '13 07:09

copenndthagen


2 Answers

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

like image 166
Sambuca Avatar answered Nov 08 '22 14:11

Sambuca


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  
like image 39
Ruchira Gayan Ranaweera Avatar answered Nov 08 '22 13:11

Ruchira Gayan Ranaweera