Multi-Module Maven Projects: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 30: Line 30:
A multi-module project is defined by a ''parent'' POM referencing one or more submodules. The essential elements are the packaging, which is of type "pom", and the list of modules.
A multi-module project is defined by a ''parent'' POM referencing one or more submodules. The essential elements are the packaging, which is of type "pom", and the list of modules.


<pre>
<project>
     ...
     ...
     <packaging>pom</packaging>
     <packaging>pom</packaging>
     ...
     ...
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>
    ...
</project>
</pre>


</pre>
Each <tt><module></tt> element corresponds to a ''subdirectory'' of the top level project directory. Maven will look into these subdirectories for <tt>pom.xml</tt> files. Each module will have its own independent source hierarchy.


=Organizatorium=
=Organizatorium=


* The modules do not need to specify their <tt><groupId></tt>, as it is inherited from their parent, and thus redundant.
* The modules do not need to specify their <tt><groupId></tt>, as it is inherited from their parent, and thus redundant.

Revision as of 17:25, 4 November 2016

External

Internal

Overview

For guidelines on when it is appropriate to use modules, and when separate projects, see "When We Should Use Modules ?" section.

The Reactor

When We Should Use Modules?

Two major benefits of a multi-module project are that all the parts can be built with a single command, and Maven handles the correct build order.

Modules and Versions

Different modules of the same project can have different version.

POM Structure

The Parent POM

A multi-module project is defined by a parent POM referencing one or more submodules. The essential elements are the packaging, which is of type "pom", and the list of modules.

<project>

   ...
   <packaging>pom</packaging>
   ...
   <modules>
       <module>module1</module>
       <module>module2</module>
   </modules>
   ...

</project>

Each <module> element corresponds to a subdirectory of the top level project directory. Maven will look into these subdirectories for pom.xml files. Each module will have its own independent source hierarchy.

Organizatorium

  • The modules do not need to specify their <groupId>, as it is inherited from their parent, and thus redundant.