How to properly setup maven Spring Boot multi module project?

Viewed 151

After some research try and fail, I am still not able to put my head around a clear way to do the following:

Project-All - "Ability to combine Module #1 & Module #2 and to run in dev (Test full solution)"
|
+ Module_1 - "Ability to run independently in dev (Different dev team)"
| - pom.xml
+ Module_2 - "Ability to run independentlyin dev (Different dev team)"
| - pom.xml
- pom.xml

I would like to build and run module_1 and module_2 separately, as well as assembled. After trying Assembly Plugin for Maven without significant success (Or over-complicated solution), I am now trying with Spring Boot Plugin for Maven which seems way simpler to use.

So would we have any recommendation on how to properly build such setup with Spring Boot Plugin for Maven?

Thanks

1 Answers

Here is one approach you can try :

In the main module POM you could use the maven release plugin like follows :

...
<packaging>pom</packaging>
   <modules>
      <module>module1..</module>
      <module>module2..</module>
</modules>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <configuration>
                <goals>install</goals>
                <autoVersionSubmodules>true</autoVersionSubmodules>
            </configuration>
        </plugin>
    </plugins>
</build>

If you wish to build the submodules in such a way that they could run on its own :

your could use maven repckage goal in the module pom as follows:

 <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

There is possibility providing the name of the main class in this configuration. Checkout the official documentation

Related