Débora
Débora

Reputation: 5952

custom parent pom with org.springframework.cloud and spring-boot-starter-parent

I have couple of spring cloud projects and wish to put all common dependencies into my own parent pom too. Many samples shows how to do it with <dependencyManagement>. But in my case with spring-boot-starter-parent and org.springframework.cloud, it seems to be not working using dependency management as the parent has already become 'spring-boot-starter-parent' and dependency management is also there having org.springframework.cloud. Following is one of my spring cloud projects' pom files.

<groupId>com.demo</groupId>
<artifactId>demo-customer-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo-customer-service</name>
<description>Demo project for Spring Boot</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencyManagement>
    <dependencies>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>  

as above, there are two parents: org.springframework.boot starter parent and cloud. So how can I have my own parent ?

Any suggestion please how the parent and the child pom files should be ?

Upvotes: 1

Views: 1719

Answers (1)

miskender
miskender

Reputation: 7968

The pom you provided can perfeclty become a parent pom. Parent poms can have parent's themself also. It is commonly used and if you check the projects you are using on github they have chain of parents.
For example spring-cloud-build-dependencies has spring-boot-dependencies as parent. spring-boot-dependencies has spring-boot-build as parent.

Inside your parent pom, dependencies defined inside <dependencies></dependencies> will be added to all the childs of your parent. If all your childs are using these dependencies you can add them in this tag. (I generally add unit test dependencies here, but you can add anything)
Parent poms usualy located one folder above of childs pom.xml. (But <relativePath> can be used if it is elsewhere)

|-parent pom.xml
|-child project folder
|--child pom.xml

Upvotes: 2

Related Questions