カスタム親を持つSpring Bootの依存関係管理

カスタム親を使用したSpring Boot依存関係管理

1. 概要

Spring Bootは、SpringBootアプリケーションを簡単に作成するための親POMを提供します。

ただし、using the parent POM may not always be desirable, if we already have a parent to inherit from.

このクイックチュートリアルでは、親スターターなしでBootを使用する方法を見ていきます。

2. Spring Boot親POMなし

The parent pom.xml takes care of dependency and plugin management.そのため、それを継承すると、アプリケーションで貴重なサポートが提供されるため、通常、Bootアプリケーションを作成するときに推奨されるアクションです。 親スターターに基づいてアプリケーションを構築する方法の詳細については、our previous articleを参照してください。

ただし、実際には、we may be constrained by design rules or other preferences to use a different parent.

幸い、Spring Bootは、親スターターから継承する代わりの方法を提供しますが、それでもいくつかの利点があります。

scope=importspring-boot-dependenciesアーティファクトを追加することによるIf we don’t make use of the parent POM, we can still benefit from dependency management


     
        
            org.springframework.boot
            spring-boot-dependencies
            1.5.6.RELEASE
            pom
            import
        
    

次に、Springの依存関係を追加し、Spring Bootの機能を利用し始めることができます。


    org.springframework.boot
    spring-boot-starter-web

On the other hand, without the parent POM, we no longer benefit from plugin management.これは、spring-boot-maven-pluginを明示的に追加する必要があることを意味します。


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

3. 依存関係バージョンのオーバーライド

Bootによって管理されているものとは異なるバージョンを特定の依存関係に使用する場合は、spring-boot-dependenciesを宣言する前に、dependencyManagementセクションで宣言する必要があります。


    
        
            org.springframework.boot
            spring-boot-starter-data-jpa
            1.5.5.RELEASE
        
    
    // ...

対照的に、dependencyManagementタグの外側で依存関係のバージョンを宣言するだけでは機能しなくなります。

4. 結論

このクイックチュートリアルでは、親pom.xml.なしでSpring Bootを使用する方法を説明しました。

例のソースコードはover on GitHubにあります。