Search code examples
mavenspring-bootmaven-3spring-boot-starter

How to have another parent dependency as well as Spring Boot parent in maven pom.xml file?


I am currently developing a Spring Boot multi-module project.

When you set up a Spring Boot project, in your pom.xml you are required to have a parent reference to Spring Boot, e.g.

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

What I would like to have is my project be a submodule Spring Boot project of a wider project (i.e. I would like to package them together under one project folder in a Repo).

Now, normally in order to setup multi-module project, you put the parent pom info like above into your submodule pom.xml.

But with the requirement of having the Spring Boot parent as a requirement, it is not possible to do so.

I've seen suggestions already on the net recommending to move my submodule out and have it as a separate project independently but I think this would be my last resort right now unless that is the only way to go.

Does anyone have any ideas on how to achieve what I want or whether what I want to achieve is practically feasible or not?

Looking forward to hearing option...


Solution

  • You can't have different parent POMs. Unless you want to extend the Boot parent into your own parent POM and work from there, which might be feasible.

    The other option is to use the Spring Boot BOM with DependencyManagement, it's a tiny bit more of less concise when you want to override dependencies e.g. normally you just override a maven property.

    However when using the BOM you need to order the overrides, and then the boot BOM last in a dependency management tag. Example from the Spring Docs,

    <dependencyManagement>
    <dependencies>
        <!-- Override Spring Data release train provided by Spring Boot -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-releasetrain</artifactId>
            <version>Fowler-SR2</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.10.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
    </dependencyManagement>
    

    See, https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html#using-boot-maven-without-a-parent

    For more information on setting up a Spring Boot project without using the Spring Boot Parent POM.