In this tutorial I will explain you how to create multi-modules maven project in Eclipse. This kind of project is a good design when you want to group similar projects and reduce the duplication in code. A multi-module project is built from a parent pom that manages a group of submodules. In most cases, the parent pom is located in the project’s root directory and must have packaging of type pom. Now, the submodules are regular Maven projects and have packaging type different than pom, and they can be built separately or through the parent pom.
Creating Multi-modules Project in Eclipse
Please follow below steps to create the multi-modules maven project.
- Create New maven project in Eclipse menu. Select Archetype as
maven-archetype-quickstart. In next window input Group Id, Artifact Id etc. For example, Group Id – jeejava, Artifact Id – spring-microservices, Version – by default auto populated. Now open the
pom.xmlfile and change the packaging type as pom. If you find any problem on the project then simply do
Maven -> Update Project.
- Now do right click on the spring-microservices project and click
New -> Other. In the Wizard window select
Maven -> Maven Module. In the next window input Module Name as
user-service. Make sure that Parent Project selected as
spring-microservices. On next window select Archetype as
maven-archetype-quickstart. In next window accept all defaults and click Finish. Now you will see in the parent project’s (spring-microservices) pom has been updated with
<modules/>tag. Now open the user-service project’s pom.xml file and remove
<version/>tags. Because these two values will be inherited from parent project.
- Now create another module
email-servicein the similar way as you have created
user-service. Remove the
<version/>tags from the pom.xml file. Now again you will see the parent’s pom file has been updated to include the
The project structure will look like similar to the below image
Now you can add dependencies, plugins etc in individual child pom file as per the project requirements.
You can also add common dependencies, plugins etc. in the parent project’s pom file and those dependencies will be automatically inherited in the child’s pom file.
If you want to override any inherited dependency in child pom then you need to declare the same dependency in child’s pom file.
Building the Project
You can build the entire project with all modules from the parent pom file or you can also build the individual module from its own pom file.
Thanks for reading.Tags: apache maven • maven multi module • multi module • multi module project