Danny Goodwill
Danny Goodwill

Reputation: 145

Using Maven's shade plugin for third party libraries?

TL;DR version

Can Maven's shade plugin affect third party libraries?

Longer version

My co-worker and I have been arguing about using Maven's shade plugin to fix dependency errors on third party libraries. We have the following dependency hierarchy:

foo (our project)
+--- bar:1.0.0
|    \--- baz:1.1.1
\--- boo:1.0.0
     \--- baz:2.2.2

(foo depends on bar and boo; both depend on different versions of baz)

The problem is, bar and boo cannot use a different version of baz. In our project we do not rely directly on baz, but we do rely on bar and boo.

My co-worker says we can use Maven's shade plugin to shade baz:1.1.1 or baz:2.2.2 to make it work, but it doesn't sound logical because for it to work it would have to modify the signatures in the class files of bar or boo. Surprisingly though, he did manage to get through the NoSuchMethodError he's been dealing with using shade, and to be honest I'm not quite sure how..

So, does shade actually affect third party libraries and not just my own code?
Also, if it doesn't, is there a way to solve the above conflict?

Upvotes: 3

Views: 572

Answers (1)

Robert Scholte
Robert Scholte

Reputation: 12345

Nice question. Trying to shade baz in foo won't work, because Maven will choose only one of the two baz dependencies. Shading (with relocation) baz would be weird, because there will be new classes which bar or boo won't recognize. What I would try is setting up a multimodule project with foo, bar-shaded and boo-shaded. For foo add dependencies on these modules. Ensure that the relocations of baz are different.

Upvotes: 1

Related Questions