Maven Nested Modules - Second Level Children

6.2k views Asked by At

I read a lot about maven multi module projects and came to the conclusion that I want to use the following approach:

root
  --pom.xml
  --parent
    --pom.xml
  --module-a
    --pom.xml
  --module-b
    --pom.xml

see here

But now I am a bit struggling on how to handle second/third/n level modules, e.g. module-a has also multiple sub-modules, especially for deep hierarchies with a whole lot of modules.

Do I see module a again as a root then resulting in the following structure:

root
  --pom.xml
  --parent
    --pom.xml
  --module-a
    --pom.xml
    --parent-module-a
        --pom.xml
    --module-a-1
        --pom.xml
    --module-a-2
        --pom.xml
  --module-b
    --pom.xml

Or would I put the sub-modules of module-a still in the root directory:

root
  --pom.xml
  --parent
    --pom.xml
  --module-a
    --pom.xml
  --module-b
    --pom.xml
  --module-a-1
    --pom.xml
  --module-a-2
    --pom.xml

Thank you for your help!

1

There are 1 answers

1
Michał Kalinowski On BEST ANSWER

Yeah, be there some time ago. To be honest, after trying things, I believe it's really matter of taste. For me it's much more clear to stick with root's pom.xml as a parent and not doing dedicated module for it. It's also the actual default of Maven, since <relativePath> for parent is .. initially. As you see in your case, this advantage is even more important when scaling Maven structure further than just 1 level.

I can image an advantage of having kind of Maven-based logic within this parent module, such as assembly definition or something like that. Then it provides a root directory for standard Maven directory layout where you can put your stuff. However, I really don't remember the situation when I would find it useful, doing Maven for many years now, including really big codebases with hundreds of modules as well.