Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create maven module from 2 different parents?

Tags:

I'm adding new maven module to project. It will use spring-boot. Old modules are not using it. So, my new module must be child of parent project but at the same time must be a child of spring-boot-starter-parent. How can I make my project child of 2 different parent?

My current parent

<parent>
    <groupId>com.somegroup</groupId>
    <artifactId>Parent</artifactId>
    <version>1.0</version>
</parent>

Spring-boot parent

<parent>
    <!-- Your own application should inherit from spring-boot-starter-parent -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
</parent>
like image 605
Furkan Yavuz Avatar asked Feb 08 '17 12:02

Furkan Yavuz


1 Answers

Since Maven project can have only one parent you can use a different approach. Instead of inheritance, you can import spring-boot-dependencies in the dependency management section and keep the original parent.

<parent>
    <groupId>com.somegroup</groupId>
    <artifactId>Parent</artifactId>
    <version>1.0</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

You can read about the constraints in the official documentation, which are basically about the way you change the version of dependencies provided by Spring Boot.

like image 109
Daniel Olszewski Avatar answered Sep 23 '22 10:09

Daniel Olszewski