Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi module project with spring boot

Tags:

java

spring

maven

I am creating a project with spring-boot.

Spring boot maven structure mandates that it has a parent defined to spring-boot-starter-parent.

I have a situation where I would like to package my application as a multi-module structure where I define modules which contain functionality related to a geography.

Something like this, each module has a jar packaging,

parent Pom
|
|-----------Core module
|
|-----------India Module
|
|----------Africa Module
|
|--------- Europe Module

Now, I can package my application depending on geography using maven profiles where in India profile only core module and India module are included and packaged.

How can I achieve it using spring boot where my parent is already defined to spring-boot-starter-parent?

like image 725
alok ailawadi Avatar asked May 13 '15 06:05

alok ailawadi


2 Answers

There are two ways one can do it,

  1. use dependencyManagement in your parent pom as in

     <dependencyManagement>
        <dependencies>
           <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <type>pom</type>
            <version>1.2.3.RELEASE</version>
            <scope>import</scope>
        </dependency>
    </dependencies>
    

  2. This is the way I am doing it. The root POM (with pom packaging) has spring boot as parent

    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>1.2.3.RELEASE</version>
    </parent> 
    

the module poms have root pom as parent. The core module POM adds has dependency on other modules. It also has 'spring-boot-maven-plugin' to create the fat jar.

The spring context is started with java -jar Core_xxx.release.jar

Off course if you have organization wise parent POM then first option would be more appropriate.

like image 52
alok ailawadi Avatar answered Sep 19 '22 00:09

alok ailawadi


Right now you can solve that problem using official Spring guidline and create Spring Boot Multi-Module project. Just follow the instruction https://spring.io/guides/gs/multi-module/

like image 22
BSeitkazin Avatar answered Sep 23 '22 00:09

BSeitkazin