首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么在dependencyManagement中需要spring-boot-dependencies?

为什么在dependencyManagement中需要spring-boot-dependencies?
EN

Stack Overflow用户
提问于 2017-10-28 06:11:01
回答 2查看 9.7K关注 0票数 3

Spring documentation Using Spring Boot without the parent POM显示对spring-boot-dependencies的依赖项已添加到dependencyManagement部分。这真的是正确的吗?

spring-boot-dependencies为所有依赖项指定版本属性。但是,这些属性在使用spring-boot-dependencies的POM中不可用。想必,这是因为spring-boot-dependenciesdependencyManagement中。

spring-boot-dependencies仅包括dependencyManagementpluginManagement。因此,在不添加不必要的依赖项的情况下,似乎可以包含spring-boot-dependencies作为依赖项(而不是dependencyManagement)。

那么为什么要将spring-boot-dependencies包含在dependencyManagement中呢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-28 06:23:27

这绝对是正确的。请参阅Using Spring Boot without the parent POM

票数 1
EN

Stack Overflow用户

发布于 2017-10-28 07:12:14

那么,为什么要将

-boot-dependencies包含在dependencyManagement中呢?

假设您有一个名为projectA的项目,并将spring-boot-dependencies添加到pom.xml中的dependencyManagement部分。

代码语言:javascript
运行
复制
<project>
  <groupId>com.iovation.service</groupId>
  <artifactId>projectA</artifactId>
  <version>1.0.0-SNAPSHOT</version>

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

  <dependencies>
    <!-- Spring Boot Dependencies -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
      </dependency>
  ...
</project>

如果仔细观察,您会发现在dependencies部分下声明的所有Spring Boot依赖项都不需要指定version。它从dependencyManagement部分中指定的spring-boot-dependencies版本派生version

依赖项管理的优势

  • 它通过在一个地方指定Spring Boot版本来集中依赖信息。在从一个版本升级到another.
  • Subsequent的过程中,Spring Boot依赖声明真的很有帮助,只需要提到库名称,而不是任何版本。在多模块项目中特别有用
  • 它避免了项目中不同版本的spring boot库的不匹配。
  • 无冲突。
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46984069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档