gradle - Gradle依赖解析的逻辑是什么
问题描述
在 Gradle 6.7 中,我们需要dependencyManagement.dependencies
为项目设置默认值。
最近,有人dependency
用dependencySet
.
dependencySet(group: 'org.springframework.boot', version: "2.2.11.RELEASE") {
entry 'spring-boot-devtools'
entry 'spring-boot-dependencies'
entry 'spring-boot-devtools'
entry 'spring-boot-starter-aop'
entry 'spring-boot-starter-cache'
entry 'spring-boot-starter-webflux'
...
现在,在发现一些 CVE 警报后,我发现 Gradle无论如何spring-boot-starter-cache
都会解析。2.2.8
我不确定它从哪里获得该版本:我们的项目中没有它,并且 deps 树看起来好像是我们自己要求的(它在级别 0)。
+--- org.springframework.boot:spring-boot-starter-cache -> 2.2.8.RELEASE
当我像以前一样明确添加项目时,
dependency 'org.springframework.boot:spring-boot-starter-cache:2.2.11.RELEASE'
然后它最终被解析为 2.2.11。
+--- org.springframework.boot:spring-boot-starter-cache -> 2.2.11.RELEASE
在 Maven 中,依赖管理非常简单,与此相比:您可以使用依赖管理和 BOM 来控制它,并且一切正常,这并不奇怪。
所以也许我在 Gradle 的逻辑中遗漏了一些东西,即使在阅读了依赖管理指南之后。
如何使用类似 BOM 的dependencySet
方式一次控制所有entry
-es?还是我有错误的假设?
解决方案
在 Gradle 6.7 中,我们需要
dependencyManagement.dependencies
为项目设置默认值。
不要将 Spring 的依赖管理 Gradle 插件与 Gradle 的原生依赖管理功能混淆。尽管他们实现了相同的目标,但他们以非常不同的方式实现目标。
我不确定它从哪里获得该版本:我们的项目中没有它,并且 deps 树看起来好像是我们自己要求的(它在级别 0)。
您可以使用该dependencyInsight
任务来获取有关特定依赖项以及选择特定版本的原因的更多信息。
./gradlew dependencyInsight --dependency org.springframework.boot:spring-boot-starter-cache
有关更多详细信息,请参阅查看和调试依赖 项。
如何使用类似 BOM 的
dependencySet
方式一次控制所有entry
-es?还是我有错误的假设?
Spring 依赖管理插件的文档很清楚你需要做什么来实现这一点:https ://docs.spring.io/dependency-management-plugin/docs/current/reference/html/#dependency-management-configuration- dsl 依赖集
如果它没有按您的预期工作,那么您需要调试您的依赖项,正如我上面链接的那样。
同样从你的例子中,我猜你有一个典型的 Spring Boot 应用程序,应用了 Spring Boot Gradle 插件。如果是,那么 Spring Boot Gradle 插件会检测是否应用了 Spring 依赖管理插件并自动导入 Spring Boot BOM。所以应该不需要像你一样管理 Spring 特定的依赖项。
推荐阅读
- php - 使用 ajax 调用加载页面的一部分。但是表单按钮不起作用
- javascript - 如何将(通过 javascript)动态创建的 HTML 表的数据发送到 PHP 文件进行处理?
- mysql - 如何获取仅与指定用户相关的第一个线程?
- angular - 如何将ngModel值传递给Angular 6中的组件
- java - Jetty Endpoint除了网络连接外还能代表什么连接
- python - 关闭 tkinter 顶级窗口
- angular - 带有自定义组件的 Angular 延迟加载模块
- c# - 如何在文本框中拆分文本
- python - python中的lapply等效函数
- java - 有没有办法在 JAVA 中使用 dd-MM-yyyy 格式的日期列对 SQLServerBulkCSVFileRecord 进行 SQLServerBulkCopy?