gradle – 无法解释的依赖版本出现

huangapple go评论73阅读模式
英文:

gradle - unexplainable dependency version coming

问题

我有一个使用Spring Boot 2.6.1的应用程序,我在测试中使用Selenium。

我使用的是selenium-java版本4.6.0

testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.6.0'

但是,被拉取的传递依赖关系都是旧版本(主要是3.141.59),这导致在运行时出现一些问题,例如找不到类等:

gradle – 无法解释的依赖版本出现

我可以手动覆盖所有这些依赖关系,但这似乎不是正确的方式。

不管怎样,这些版本是从哪里来的呢?我没有在任何地方定义它们,所以我希望拉取https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.6.0 中显示的所有版本。

英文:

I have a Spring Boot 2.6.1 application for which I use Selenium during my tests.

I am using selenium-java 4.6.0

testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.6.0'

but the transitive dependencies that are pulled are all older versions (mostly 3.141.59), which leads to some issue at runtime, with classes not found etc :

gradle – 无法解释的依赖版本出现

I can override all these dependencies manually, but that doesn't look like the right way..

anyway, where are these versions coming from ? I am not defining them anywhere, so I would expect all the versions showed in https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.6.0 to be pulled.

答案1

得分: 1

Spring Boot 依赖管理又一次让我困惑,它大部分时间非常有用,但有时像这里一样令人困惑...

如在 Spring Boot 2.6 文档中所述,Selenium 由 BOM(我之前不知道)管理,令人惊讶的是 v3.141.59 在那里定义 - 所以它来自那里,而我没有在任何地方定义它。

https://docs.spring.io/spring-boot/docs/2.6.6/reference/html/dependency-versions.html#appendix.dependency-versions.properties

gradle – 无法解释的依赖版本出现

所以解决方案非常简单:我们只需在 Gradle 构建文件中覆盖版本

ext['selenium.version'] = '4.6.0'

dependencies {
    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java' 
    ...
}

然后所有“正确”的依赖版本现在都会生效。

英文:

I again got tricked by Spring Boot dependency management, which is most of the time super useful, but sometimes confusing like here...

As documented in Spring boot 2.6 , Selenium is managed by the BOM (I was not aware of this), and what a surprise : v3.141.59 is defined there - so this is where it's coming from, without me defining it anywhere.

https://docs.spring.io/spring-boot/docs/2.6.6/reference/html/dependency-versions.html#appendix.dependency-versions.properties

gradle – 无法解释的依赖版本出现

So the solution is quite simple : we simply need to override the version in the gradle build file

ext['selenium.version'] = '4.6.0'

dependencies {

    testImplementation group: 'org.seleniumhq.selenium', name: 'selenium-java' 
    ...
}

and all the "right" dependencies versions are now coming.

huangapple
  • 本文由 发表于 2023年3月4日 00:30:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75629623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定