Select Page

Maven multi module support in M2Eclipse

Maven multi module support in M2Eclipse

Maven projects are created using the New “Maven projects” from M2Eclipse, see here for more details

Maven Modules are different beast, as they are suppose to have a parent in their hierarchy, if you use #Maven
you are already understanding what the differences are.

You can get in troubles if you try to make a lot of #maven projects in eclipse, although it may seems natural to do so. A lot
of people have gone that path, and this may work if you use the relativePath trick

  • parent (contains the super pom)
  • common-api, reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • common-core reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • common-spring reference the parent using the <relativePath>../parent/pom.xml</relativePath>
  • services-api   …you get the idea
  • services-core
  • services-spring

Here is an example for common-spring:


 Do not make everything a Maven project!

With such a mapping you’ll get in troubles! not all plug ins seems to support this kind of trick (relativePath)
In the maven reactor (maven-deploy, maven-release for example). It is a lot wiser to represent
your product or project also in eclipse in a tree manner. This will break the complexity, introduce
more flexibility, so why not just using maven modules??
Maven2 recommend to represent modules in a tree manner

|--- parent                                (packaging : pom)
|        | common                       (packaging : pom)
|                   |common-api       (packaging : any)
|                   |common-core     (packaging : any)
|                   |common-spring   (packaging : any)
|        | services                        (packaging : pom)
|                   |services-api        (packaging : any)
|                   |services-core      (packaging : any)
|                   |services-spring    (packaging : any)

To achieve that Goal, M2Eclipse use a trick and put all modules (common-xxx and services-xxx) in the
same maven project (parent) while displaying a workspace that look like “project flat”…

First create your product or project using a Maven Project


focus on that project, and right click New… Others … Maven Module


click Next, in the next page, choose a POM packaging, as this module will contains module
definition (aggregation of sub modules common-api, common-core, …)

The results is what maven expect: a parent directory with a set of modules and pom’s


The workspace fake the view and show maven modules as what I call “ghost projects”

Any changes in these “ghost projects” open in fact the Maven project (remember in fact
the code is there), so any change in common-api force you to sync and version the Maven project.

on the file system, it is even more visible, there is only one maven project (parent) and all its modules
are interlinked into it!

|--- myProduct                                      (packaging : pom)
|        | component-common                 (packaging : pom)
|                   |module-common-api       (packaging : any)
|                   |module-common-core     (packaging : any)
|                   |module-common-spring   (packaging : any)
|        | component-services                  (packaging : pom)
|                   |module-services-api        (packaging : any)
|                   |module-services-core      (packaging : any)
|                   |module-services-spring    (packaging : any)

you can create an unlimited number of modules interlinked in the maven project…
Some open source framework, prefers to name their first module level component-xxx, then all other modules-xxx

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.