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. The packaging type in parent pom file should pom.
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 children pom files 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.
Thanks for reading.Tags: apache maven • maven multi module • multi module • multi module project