具有相同子依赖关系的不同版本的Maven依赖关系 [英] Maven dependencies with different versions of the same sub-dependency

查看:247
本文介绍了具有相同子依赖关系的不同版本的Maven依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Maven依赖项存在这种情况:

I have this scenario with my Maven dependencies:

  • X1需要D2.2.
  • Y1需要Z1,而D1需要D2.1.

如果我强迫每个人都使用D2.2,则Z1在运行时会失败,因为它需要D2.1中的类版本(在D2.2中不再存在).如果我强迫所有人使用D2.1,则X1会失败,因为它需要一个新版本的类,而该类现在在D2.2中.将Z1升级到最新版本无效,因为它仍使用D2.1. X1和Y1也是如此.

If I force everyone to use D2.2, then Z1 fails at runtime because it needs a version of a class in D2.1 (which is no longer in D2.2). If I force everyone to use D2.1, then X1 fails because it needs a newer version of a class, which is now in D2.2. Upgrading Z1 to the latest version has no effect because it still uses D2.1. The same goes for X1 and Y1.

我该如何进行这项工作?

How can I make this work?

谢谢, 阿尔瓦罗(Alvaro)

Thanks, Alvaro

推荐答案

您刚刚遇到了多重继承的原因在Java中是不允许的.它甚至可以推断出来,即所谓的 Nixon Diamond 作为钻石依赖类比.

You have just encountered the diamond dependency problem. It's a real pain, and it shows up wherever there is a order-like relationship. Dependency is order-like, so is inheritance, which is the reason that multiple inheritance is not permitted in Java. It even shows up in inference, with the so-called Nixon Diamond as the diamond dependency analog.

要解决此问题,如果您有权访问Z1,或者它是开源的,请对其进行修补/派生/修改以使用D2.2,然后修改/分叉/修补Y1以使用您修补的Z1.

To solve this, if you have access to Z1, or if it's open source, patch it / fork it / modify it to use D2.2, then modify/fork/patch Y1 to use your patched Z1.

如果您有自己的私有/镜像工件存储库,我建议进行修补.创建一个构建作业,以克隆开源版本,进行文件修改,构建并将其发布到工件仓库.另外,也可以进行开源更改.

I recommend doing patching if you have your own private/mirrored artifact repository. Create a build job that clones the open-source version, make file modifications, build it and publish to your artifact repo. Alternatively, or in addition, make the open source change.

祝你好运.

这篇关于具有相同子依赖关系的不同版本的Maven依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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