【问题标题】:Spring boot gradle dependencies managmentspring boot gradle 依赖管理
【发布时间】:2022-12-23 22:28:56
【问题描述】:

我有以下渐变设置:

plugins {
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.springframework.boot:spring-boot-starter-amqp'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
}

如何锁定或准确指定所有依赖库的版本,如何检查与其他库的兼容性并选择最新和更新的库?

据我了解-spring boot 不需要指定 spring 框架?

  1. 检查了其他 Stackoverflow 帖子。
  2. 检查兼容性矩阵。

【问题讨论】:

    标签: spring spring-boot gradle


    【解决方案1】:

    要锁定或指定 Gradle 构建中所有依赖项的确切版本,您可以使用 dependencyManagement 块。此块允许您定义项目中使用的依赖项的版本,这将确保所有依赖项始终使用相同的版本。

    以下是如何在 Gradle 构建中使用 dependencyManagement 块的示例:

    dependencyManagement {
      imports {
        mavenBom "org.springframework.boot:spring-boot-dependencies:3.0.0"
      }
      dependencies {
        dependency "org.springframework.boot:spring-boot-starter-web"
        dependency "org.springframework.boot:spring-boot-starter-actuator"
        dependency "org.springframework.boot:spring-boot-starter-aop"
      }
    }
    

    在此示例中,mavenBom 导入指定正在使用的 Spring Boot 版本,即 3.0.0。 dependencies 块然后列出项目中使用的所有 dependencies,并且这些 dependencies 的版本自动解析为与 Spring Boot 3.0.0 兼容的版本。

    您可以通过查阅 Spring Boot 兼容性矩阵来检查项目中 dependencies 的兼容性。这个矩阵列出了Spring Boot的版本以及各个版本的Spring Boot兼容的dependencies的版本。

    Spring Boot 包含 Spring 框架作为传递依赖项,因此您无需在 Gradle 构建中将 Spring 框架指定为依赖项。但是,如果您想使用特定版本的 Spring 框架,您可以将其作为依赖项包含在构建的 dependencies 块中。

    我希望这有帮助!如果您有任何问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 2019-01-30
      • 2017-09-29
      • 2013-06-15
      • 2021-03-13
      • 2016-09-17
      相关资源
      最近更新 更多