为什么要设计使用Spring Boot启动程序依赖项,而与Maven的传递依赖项机制的意图相反? [英] Why were Spring Boot starter dependencies designed to be used contrary to the stated intent of Maven's transitive dependency mechanisms?

查看:83
本文介绍了为什么要设计使用Spring Boot启动程序依赖项,而与Maven的传递依赖项机制的意图相反?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Maven依赖文档旨在明确列出所有编译依赖项,而不是在编译时可传递地使用

According to the Maven dependency documentation it is intended that all compile dependencies be explicitly listed, rather than transitively used at compile time:

原本打算[transitive编译依赖项]应该在运行时范围内,以便所有编译依赖项都必须明确列出-但是,在某些情况下,您依赖的库会从另一个库扩展一个类,从而迫使您在编译时可用.因此,即使编译时间相关性是可传递的,它们仍保留为编译范围.

it is intended that [transitive compile dependencies] should be runtime scope instead, so that all compile dependencies must be explicitly listed - however, there is the case where the library you depend on extends a class from another library, forcing you to have available at compile time. For this reason, compile time dependencies remain as compile scope even when they are transitive.

Spring Boot具有启动器"依赖项的概念.从Spring Boot自己的文档(以及我在Spring Boot自己的示例和其他地方看到的许多使用示例)中,很明显,这些示例旨在可传递地引入许多其他依赖项,以便在运行时和编译时使用.根据 Spring Boot的文档:

Spring Boot has a notion of "Starter" dependencies. From Spring Boot's own documentation (as well as the many examples of use I've seen both within Spring Boot's own examples and elsewhere), it is clear that these are intended to transitively bring in numerous other dependencies to be used at both runtime and compile. Per Spring Boot's documentation:

启动器是一组方便的依赖项描述符,您可以将其包含在应用程序中.您可以一站式购买所需的所有Spring和相关技术,而不必遍历示例代码并复制依赖项描述符的粘贴负载.例如,如果您想开始使用Spring和JPA进行数据库访问,只需在项目中包括spring-boot-starter-data-jpa依赖项,就可以了.

Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go.

入门程序包含许多启动项目并快速运行所需的依赖项,并且具有一组一致的受支持的托管可传递依赖项.

The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies.

使用这种机制可传递性地引入编译范围的依赖项似乎与Maven正式打算如何使用它们的意图背道而驰. Maven dependency:analyze 插件目标,当直接使用Maven启动器依赖项时显示警告.例如,在Spring Boot自己的"入门"示例中运行mvn dependency:analyze会生成以下输出:

Using this mechanism to transitively bring in compile-scoped dependencies seems to be at odds with the intent of how Maven officially intends them to be used. One place that makes this abundantly clear is the Maven dependency:analyze plugin goal, which displays warnings when the Maven starter dependencies are used directly. For instance, running mvn dependency:analyze on Spring Boot's own "Getting Started" example generates the following output:

[WARNING] Used undeclared dependencies found:
[WARNING]    org.springframework:spring-web:jar:4.3.6.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot-test:jar:1.5.1.RELEASE:test
[WARNING]    org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.1.RELEASE:test
[WARNING]    org.springframework:spring-test:jar:4.3.6.RELEASE:test
[WARNING]    org.springframework.boot:spring-boot:jar:1.5.1.RELEASE:compile
[WARNING]    org.hamcrest:hamcrest-library:jar:1.3:test
[WARNING]    org.springframework:spring-context:jar:4.3.6.RELEASE:compile
[WARNING]    junit:junit:jar:4.12:test
[WARNING]    org.springframework.boot:spring-boot-autoconfigure:jar:1.5.1.RELEASE:compile
[WARNING]    org.springframework:spring-beans:jar:4.3.6.RELEASE:compile
[WARNING] Unused declared dependencies found:
[WARNING]    org.springframework.boot:spring-boot-starter-web:jar:1.5.1.RELEASE:compile
[WARNING]    org.springframework.boot:spring-boot-starter-test:jar:1.5.1.RELEASE:test
[WARNING]    org.springframework.boot:spring-boot-starter-actuator:jar:1.5.1.RELEASE:compile

我的问题是,为什么Spring Boot启动程序模式的设计方式与基本构建系统的既定意图直接相反.是否有关于该主题的任何已发布讨论,或在任何地方给出了说明?

My question is why the Spring Boot starter pattern was designed in such a way to be directly contrary to the stated intent of the underlying build system. Are there any posted discussions on the topic, or explanations given anywhere?

推荐答案

看起来您已将依赖插件配置为在发生警告时失败.我认为如果您未明确声明可传递依赖项,则依赖项插件会发出警告.

Looks like you have configured dependency plugin to fail on warnings. I think dependency plugin spits out warning if you have not explicitly declared a transitive dependency.

尝试更改 <failOnWarning>true</failOnWarning><failOnWarning>false</failOnWarning>

这篇关于为什么要设计使用Spring Boot启动程序依赖项,而与Maven的传递依赖项机制的意图相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆