Reputation: 23
I am new to Spring, Spring boot, and Spring boot starter.
For my different apps I use an own parent.pom
for what the have in common. The parent.pom
contains the version numbers as properties and dependencies that use the properties as version numbers.
When using my parent.pom maven states that I have to use the "spring-boot-starter-parent"
.
How can I use my own parent.pom instead of the "spring-boot-starter-parent
"?
Meanwhile I changed the pom to this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.websystique.springboot</groupId>
<artifactId>SpringBootRestApiExample</artifactId>
<version>1.0.0</version>
<name>SpringBootRestApiExample</name>
<parent>
<groupId>my</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Add typical dependencies for a web application -->
<!-- Adds Tomcat and Spring MVC, along others -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.1.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
But now I get this warning:
dependencies.dependency.scope' for org.springframework.boot:spring-boot-starter-parent:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 27, column 1
Upvotes: 1
Views: 2460
Reputation: 727
It is also possible to import the spring-boot-starter-parent pom. So you can use your own pom as parent and you can use the dependency management from the spring boot pom.
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
...
Upvotes: 1
Reputation: 10716
You don't have to use spring-boot-starter-parent
, it's just that it has an extensive dependencyManagement
section that ensures all the Spring Boot dependencies you use in child projects have mutually compatible versions.
I typically declare spring-boot-starter-parent
as the parent POM of my parent POM. This way, you get the best of both options.
Upvotes: 6