2
votes

I've created a few Spring Boot projects, each one's POM including a spring-boot-starter-parent as a parent. Whenever a new version comes out, I currently need to manually update it in every POM.

Adding a POM dependency which already has the spring-boot-starter-parent does not help, and the Spring Boot documentation states that using an 'import' scope will only work for dependencies, and not the Spring Boot version itself.

Is there a way to define a "super-pom" which all my projects can inherit from, where I can set the Spring Boot version once, and not go through each project?

1

1 Answers

3
votes

Here is an approach you can try.

Your parent POM:

<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>
  <!-- Do you really need to have this parent? -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
  </parent>
  <groupId>org.example</groupId>
  <artifactId>my-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>Parent POM</name>
  <properties>
    <!-- Change this property to switch Spring Boot version-->
    <spring.boot.version>1.2.7.RELEASE</spring.boot.version> 
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <!-- Declare the Spring Boot dependencies you need here 
         Please note that you don't need to declare the version tags.
         That's the whole point of the import above.
    -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot</artifactId>
      </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-actuator</artifactId>
    </dependency>
    <!-- About 50 in total if you need them all -->
    ...
  </dependencies>
</project>

A child POM:

<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>
  <parent>
    <groupId>org.example</groupId>
    <artifactId>my-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>my-child</artifactId>
  <name>Child POM</name>
</project>

If you do a mvn dependency:tree on the child POM, you'll see that they are all in there.