具有相同子依赖的不同版本的 Maven 依赖

Maven dependencies with different versions of the same sub-dependency

我的 Maven 依赖项有这种情况:

如果我强制每个人都使用 D2.2,那么 Z1 在运行时会失败,因为它需要 D2.1 中的 class 版本(D2.2 中不再存在)。如果我强迫每个人都使用 D2.1,那么 X1 就会失败,因为它需要更新版本的 class,现在在 D2.2 中。将Z1升级到最新版本没有任何效果,因为它仍然使用D2.1。 X1 和 Y1 也是如此。

我怎样才能使这个工作?

谢谢, 阿尔瓦罗

您刚刚遇到了 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 作为钻石依赖类比。

要解决此问题,如果您可以访问 Z1,或者如果它是开源的,则对其进行修补/分叉/修改以使用 D2.2,然后 modify/fork/patch Y1 以使用修补后的 Z1。

如果您有自己的 private/mirrored 工件存储库,我建议您进行修补。创建一个克隆开源版本的构建作业,进行文件修改,构建它并发布到您的工件存储库。或者,或者另外,进行开源更改。

祝你好运。