Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use multi module maven project?

Tags:

maven

I'm pretty newbie in Maven. Maybe that's is reason of this question :)

Today I tried to download project called Sonar Runner and just see how it's working. It was pretty strange experience for me because this project has 4 submodules:

  • Sonar Runner - API
  • Sonar Runner - Batch
  • Sonar Runner - Distribution
  • Sonar Runner - Implementation

They have respectively: 17, 2, 8 and 13 java files.

It makes me wonder why it's so fine grained. I know that you don't know what was their reasons. But I'm curious what reasons can be.

Until now I thought that size of project is a reason or separate teams working on diffrent parts of project.

But when project has 40 java files I guess size is not the reason.

What I get when I use multi-module project instead of one big project?

I tried to find out the answer in Google but with no luck.

EDIT: I found this one: Is there any benefit in using Maven Multimodule when working in a small application?

But still with project having 40 java files. Splitting it into 4 submodules seems just ridiculous for me.

Are there any other benefits?

like image 200
zimi Avatar asked Nov 28 '14 15:11

zimi


People also ask

What is the use of multi-module Maven project?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

Why do we need multi-module projects?

Advantages of a Multi-Module ProjectIt provides a great ability to build all sub-modules only with a single command. We can run the build command from the parent module. While building the application, the build system takes care of the build order. Deployment of the applications gets very convenient and flexible.

What is the difference between Maven module and Maven project?

There is very little difference between Maven Module and Maven Project. When we create a Maven module it is mandatory to specify a parent project. As soon as we specify the parent project, <modules> … </module> is added in pom.


1 Answers

I'm almost always do multi-module Maven projects - even if I'm hacking some open-source experiment alone.

There many reasons to do multi-module projects:

  • Different parts of the code are relevant for different environments. You may want to separate API and implementation or compile-time tools from things you need in a runtime.
  • Makes sense putting different functional components in different modules.
  • Separate modules may have their own version roadmap. For instance, an API may stay very stable over a long time but the implementation will be updated often.
  • Even if you're doing a single-JAR project, you may need a separate module with test tools or separate samples/demos/tests.
  • Even if you don't need all, even with single-JAR of this it is often useful to make a parent pom and a child jar module. And move the organisational stuff to the parent pom.
  • You may need to split one module into several if you have a circular dependency. If part of A depends on B and B depends on a part of A, you may need to split A in A1 and A2.
  • I often prefer not to mix manually written and generated code in one module.

And probably much more.

These reasons are so many so since years already I prefer to start with the parent/child setup from the very start. I can't recall a single project I was involved in, which would stay single-module.

Even splitting 2-file project in 2 modules does not sound ridiculos to me, if there are reasons for this.

like image 147
lexicore Avatar answered Oct 16 '22 20:10

lexicore