Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

How to Create Multi-Module Maven Springboot Project

Hello Readers,

Today I will try to explain how we can create maven multi-module project for Springboot applications. There are multiple ways to achieve this like using maven commands but I am going to use a simple approach of using start.spring.io and then importing this created project into eclipse. Then adding the new maven modules.

Lets start.
  1. Navigate to https://start.spring.io/
  2. Select project as Maven Project, Language as Java, Spring Boot version as 2.1.3
  3. Under project matadata, enter group name as something like com.yourcomapny and artifact as project name like patient-service
  4. Under dependencies select what all the dependencies you want like Web, DevTools, Actuators etc

  5. Once the project is created, download and unzip into some location
  6. Open your Eclipse IDE, Click on Import and then import the project into eclipse as Existing maven project and then click finish
  7. Once the project got imported, change the patient-servie pom.xml packaging type to pom as shown in the picture below


  8. Now on the patient-service project, right click --> Maven --> New Maven Module Project


  9. Select the checkbox mentioning Create a simple project and provide module name as patient-service-api and then click finish
  10. Now the new maven module project is been created. After this create one more maven module project by repeating step 8 and step 9 with the new module name as patient-service-app
  11. The intention behind the multi module project creation is that in one module we will keep all the interfaces which might be required to be exposed to outside world and keeping the implementation module hidden with outside world.
  12. Now that we have a parent project and two submodules ready, it’s a time for us to have dependency of patient-service-api module onto patient-service-app like below


  13. Just type few characters of the dependency name and it will display the all relevant dependencies by that name. Select the dependency we need and click OK
  14. Once the patient-service-api dependency is added into patient-service-app module the pom.xml file of patient-service-api will look like below



  15. However, the patient-service-api pom.xml is simple one with no dependencies apart from inheriting the parent patient-service project like below




  16. The parent, i.e. patient-service pom.xml would have all springboot starter dependencies.
  17. Now reactor the main class of patient-service and move that main class to patient-service-app
  18. Right click on that main class from patient-service-app then run as Java application or if you have STS plugins added you can select run as springboot application. This will start the application on the port 8080 by default unless you have explicit port configurations.

So by following all the above steps we can have our multi-module maven springboot project ready for working.