0

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

Alvaro Mendez
  • 134
  • 2
  • 13
  • Sounds like one or both of X1 or Z1 is broken and should be fixed--although according to semver, a class shouldn't be dropped between a 2.1 and 2.2 version bump. In this case, you'll probably have to specify the dependencies to get a useful answer. – chrylis -cautiouslyoptimistic- Apr 18 '17 at 18:41
  • A class wasn't dropped in 2.2. A constructor (which had been deprecated) was converted from public to the default modifier. So now it's no longer accessible by Z1. Ugh. – Alvaro Mendez Apr 18 '17 at 19:49
  • Class, method, constructor, whatever. Public API shouldn't be removed. – chrylis -cautiouslyoptimistic- Apr 18 '17 at 22:17
  • 1
    What "should" happen isn't relevant in this situation. Thought I wish things that "should" happen were added as a mandatory compile-time check. – Larry B. Apr 18 '17 at 22:41
  • Possible duplicate of [How to include two different versions of the same dependency?](https://stackoverflow.com/questions/25989409/how-to-include-two-different-versions-of-the-same-dependency) – Flow Jun 19 '18 at 06:12

1 Answers1

3

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.

Larry B.
  • 753
  • 6
  • 21