How to Create a Multimodule Maven Project in Spring Tool Suite and Add Existing Microservices

Introduction

When you start building microservices with Spring Boot, it’s common to create each microservice as a standalone project. For small setups with just one or two services, this works fine. But once you’re in an enterprise-level e-commerce project with 5–6 microservices, managing them separately becomes messy — especially when generating JARs and deploying with Docker.

The solution? Multimodule Maven projects.

In this guide, we’ll walk step by step on how to:

    • Create a multimodule Maven project in Spring Tool Suite (STS)
    • Add existing microservices as modules
    • Clean up POM files and parent-child relationships
    • Generate all microservice JARs with a single Maven command


Why Multimodule Projects?

  • Single build command: No need to build each microservice separately.
  • Shared libraries: Common classes like Kafka events or domain models can live in a shared module.
  • Maintainability: All services are grouped under one parent project.
  • Cleaner Docker setup: Generate images easily with one Docker Compose file.

Steps to Create a Multimodule Project in STS

1. Create Parent Project

    • File → New → Maven Project → Simple Project
    • GroupId: com.ecomm.product
    • ArtifactId: ecomm-multimodule-project
    • Packaging: pom

This project will act as the parent for all microservices.

2. Move Existing Microservices Inside Parent Project 
    • Copy existing microservice folders (e.g., catalog-serviceconfig-servergatewayinventory-serviceinfo-service) into the parent project folder using System Explorer.
    • Refresh workspace and remove the old standalone projects. 
3. Update Child POMs
    • Replace spring-boot-starter-parent with the parent project reference

📄 pom.xml
<parent>
   <groupId>com.ecomm.product</groupId>
   <artifactId>ecomm-multimodule-project</artifactId>
   <version>1.0.0</version>
   <relativePath>../pom.xml</relativePath>
</parent>
  • Remove version and duplicate properties from child POMs (since they’ll come from the parent). 
4. Update Parent POM
    • Add Spring Boot parent once (instead of in every child).

    • Define common properties like Java version and Spring Cloud version.

    • Register child modules:

📄 pom.xml
<modules>
   <module>catalog-service</module>
   <module>config-server</module>
   <module>gateway</module>
   <module>inventory-service</module>
   <module>info-service</module>
</modules>
5. Import as Maven Project
  • Right-click parent → Import → Maven → Existing Maven Projects.

  • Select all modules and finish.

  • STS will show them both inside and outside the parent, but internally they belong to the parent project.

6. Build All Microservices Together

Run one command 

mvn clean package

This generates JARs for all services inside their respective target/ folders.

Adding a New Microservice

 

  • Right-click parent → New → Spring Starter Project.

  • Place it inside the parent folder.

  • Update POM to reference parent.

  • Add the module entry in parent POM.

Benefits

  • One build for all services 
  • Shared modules/libraries 
  • Simpler Docker deployment 
  • Clean & maintainable structure
  •  

Conclusion

  • With a multimodule Maven setup in STS, you can manage all your microservices from a single parent project. This not only saves time during builds but also keeps your project structure clean and scalable.

     Pro Tip: If you’re using IntelliJ, creating multimodule projects is much simpler. But with the workaround above, STS users can achieve the same!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top