Maven dependencies with different versions of the same sub-dependency

情到浓时终转凉″ 提交于 2019-12-12 01:48:38

问题


I have this scenario with my Maven dependencies:

  • X1 needs D2.2.
  • Y1 needs Z1 which needs D2.1.

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?

Thanks, Alvaro


回答1:


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.

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.

Good luck.



来源:https://stackoverflow.com/questions/43479808/maven-dependencies-with-different-versions-of-the-same-sub-dependency

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!