[스프링][메이븐] dependencyManagement와 dependencies 차이점

프로그래밍/서버2021. 2. 2. 15:50

stackoverflow.com/a/37280943/7225691

위의 링크에 설명이 꽤 잘 되어 있습니다.

(그나저나 Maven 공식 홈의 설명은 정말 안좋나 봅니다)

 

부모 POM에 정의된 <dependencies>와 <dependencyManagement>의 차이점은 크게 2가지입니다.

1. 부모 <dependencies>에 명시된 artifact들은 자식 POM에 의존성으로 항상 추가됨

2. 부모 <dependencyManagement>에 명시된 artifact들은 자식 POM의 <dependencies>에 있을 경우에만 의존성으로 추가됨. 이때 자식 POM에선 버전명을 명시하지 않아도 되고 이를 통해 자식들이 통일된 버전을 사용하도록 할 수 있음

 

음.. 그런데 위처럼 부모/자식 간의 관계에서만 쓰이는 것은 아닌 것 같네요.

 

아래 코드처럼.. 하나의 POM에서 버전 관리를 위해 쓰이는 BOM(Bill of Materials)를 쓰면 dependency에서 버전을 명시해줄 필요가 없습니다. 호환성에 대한 걱정이 하나 줄어드는 것이죠 ㅎㅎ

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

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
  </dependencies>

 

 

참고

www.baeldung.com/spring-maven-bom

 

Spring with Maven BOM | Baeldung

Learn how to use a BOM, Bill of Materials, in your Spring Maven project.

www.baeldung.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역