Maven将依赖调解策略设置为最新而不是最近 [英] Maven set dependency mediation strategy to newest rather than nearest

查看:476
本文介绍了Maven将依赖调解策略设置为最新而不是最近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以配置Maven选择冲突的最新依赖,而不是最近吗?

Can I configure Maven to choose the "newest" dependency on a conflict, rather than the "nearest"?

最新是Ivy中的默认值其他合理的依赖管理者,请参阅 http://ant.apache .org / ivy / history / 2.2.0 / settings / conflict-managers.html

The "newest" is the default in Ivy and other sensible dependency managers, see http://ant.apache.org/ivy/history/2.2.0/settings/conflict-managers.html

我发现最近策略很少是我想要的。

I find the "nearest" strategy is rarely what I want.

我正在使用Maven 3.3.3,但如果需要我可以切换版本。

I'm using Maven 3.3.3, but I can switch versions if necessary.

我知道如何覆盖Maven对个别冲突的选择,但我更愿意更改默认值,以便我不必一次检测并修复每个冲突。

I know how to override Maven's choice on individual conflicts, but I'd prefer to change the default so that I don't have to detect and fix each conflict one at a time.

(参见关于依赖调解的 Maven文档

(See the Maven docs on "Dependency mediation")

推荐答案

我可以配置在解决版本冲突时,Maven会自动使用最新版本的依赖项而不是最近吗?

,您无法将Maven的依赖关系中介策略配置为最近的其他内容。

No, you cannot configure Maven's dependency mediation strategy to anything other than nearest.

添加之前已经提出过可配置的依赖中介策略,但最终被放弃了,因为该提案涉及更改POM XSD,这在多年内没有发生过。

Adding configurable dependency mediation strategies has been proposed before, but was ultimately abandoned because the proposal involved changing the POM XSD, which has not happened in years.

为什么Maven会使用最近的策略作为默认策略?

Maven青睐最近的策略有两个原因:

The strategy of nearest is favored by Maven for two reasons:


  1. 轻松覆盖个别冲突 :对于任何特定冲突的
    依赖关系,您可以在自己的POM中指定其版本,并且离子变得最近。

  2. 可重复的构建 依赖关系图中任何位置的版本范围都可能导致构建不能重复性。 最新的调解策略会放大版本范围对构建再现性的负面影响。

  1. Easy overriding of individual conflicts: For any particular conflicting dependency, you can specify its version within your own POM, and that version becomes the nearest.
  2. Reproducible builds: Version ranges anywhere in your dependency graph can cause builds to not be reproducible. A mediation strategy of "newest" would magnify the negative impact of version ranges on build reproducibility.

但我真的想要一个不同的依赖调解策略。我该怎么办?

这些是您的最佳选择:


  1. 制作Maven扩展程序 :最近策略的使用由 NearestVersionSelector in MavenRepositorySystemUtils 。您可以创建自己的Maven扩展程序,定义您自己的< a href =https://github.com/eclipse/aether-core/blob/aether-1.0.1.v20141111/aether-util/src/main/java/org/eclipse/aether/util/graph/transformer/ ConflictResolver.java #L1151rel =nofollow noreferrer> VersionSelector 实现您选择的策略,然后在 afterSessionStart 扩展方法,将会话的 DependencyGraphTransformer 替换为使用自定义 VersionSelector 的会话。

  2. 迁移到其他构建工具 :显然。

  1. Make a Maven extension: Usage of the "nearest" strategy is specified by NearestVersionSelector in MavenRepositorySystemUtils. You could create your own Maven extension that defines your own VersionSelector that implements the strategy of your choice, then in the afterSessionStart method of your extension, replace the session's DependencyGraphTransformer with one that uses your custom VersionSelector.
  2. Migrate to another build tool: Obviously.

这篇关于Maven将依赖调解策略设置为最新而不是最近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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