Spring boot custom parent POM

Outline

Boot Spring in the previous example, we will use this parent POM.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

The parent specifies the dependence spring-boot required. But sometimes if our projects have a parent, and this time the need to introduce spring boot how to handle it?

This article will address this issue.

Parent POM is not used to introduce Spring boot

parent pom.xml mainly deal is dependent on management and use of plug-ins. Very simple to use, which is commonly used in our Spring boot in the way.

In practice, if we, for whatever reason, can not use the Spring boot comes with the parent, then we can do this:

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

The spring-boot-dependencies as a dependency dependencyManagement label can be placed. Note, scope here to use import.

Next, we can rely on spring boot is free to use, for example:

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

On the other hand, if you do not use parent POM, Spring boot comes with the plugin, we need to introduce himself:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Cover version dependencies

If we need to use and parent POM defined in different dependencies version, you can override the dependencyManagement in.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.5.5.RELEASE</version>
        </dependency>
    </dependencies>
    // ...
</dependencyManagement>

Of course, you can rely on every time the introduction of the specified version required.

Please refer to more tutorials flydean's blog

Published 86 original articles · won praise 88 · views 260 000 +

Guess you like

Origin blog.csdn.net/superfjj/article/details/104086259