Question

I am trying to build a maven project that has several modules. So I expect them to be built in the order given in the pom.xml ,but It can be seen that the order of the modules in build is not same as the order mentioned in the pom.xml file. What can be the reason for that ?

My Maven version : Apache Maven 3.0.4

Was it helpful?

Solution

Maven decides the order based on the dependencies. So if you have 3 submodules: A, B an C, you need to go into each submodule and make the dependency explicit. For example, if you go to the pom.xml of B and declare that it depends on A and C, maven will build A and C in some random order, and will build B at the end.

OTHER TIPS

Order that you mentioned in the parent pom file is also relevant in the case when there is no dependency crash between modules , that means if any module present above in the list and it depends on the module that is below it , then in this case order mentioned in POM file won't be used , Maven will use his brain and first build all the modules that are going to need by some other modules to build.

For more on build order , please have a look at this question and Maven Spec on same.

From the specs :

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:

    1. project dependency on another module in the build
    2. plugin declaration where the plugin is another modules in the build
    3. plugin dependency on another module in the build
    4. build extension declaration on another module in the build
    5. the order declared in the modules 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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top