miércoles, 13 de mayo de 2015

Dependency Hell

So it seems I'm on a roll... No long ago I stumble upon the jar hell issue, several times in a short time span and thus I write a small post about it. Now I stumble upon the Dependency Hell issue. So what is that all about??? Have you ever come across a maven error like:
failed: An API incompatibility was encountered while executing
Well if you had, the you're fu%#&. Well not that much but it's an interesting problem to have. Now I have found this article quite useful http://discursive.com/2014/03/17/maven-3-2-1-provides-a-new-cure-for-dependency-hell/, but in short:

When you have a dependency hell problem, is because maven is loading the same jar but different versions of it and they happen to be incompatible

Not really helpful right?
What it means is either, a dependency of your project of a transitive dependency is in conflict. Now when I say transitive, I mean transitive something in the third or forth degree may cause a problem. That's a dependency of a dependency of a dependency of a dependency. Not only that, plugin dependencies come into the game too.

Now all this this is lovely, how do I solve this mess???

There is no straight forward way, I'm sorry to say, at least none that I know of.
Usually  the firsts lines of the error will point you to the class and the method that is causing the problem.
From there, you first need to find which maven artifact contains that class.
One you have located that artifact, look for it in the stack trace chances are that you'll find it more than one time.
Now here is when it get's funny, you need to pick one of the versions of this artifact and take it out.
The problem is that the stacktrace is not arrange in a hierarchical way so when you see the module you want to take out it may be because it's in your pom, or it's a transitive dependency of the artifact just above (in the stack trace I mean). But it could also mean that the one above is a transitive dependency of the one just above or to levels up.

So here you will have to start using mvn dependency:tree, and play Find my artifac. Now this command will not output all the transitive dependencies but just a few levels of the whole tree (may be 2 or 3). The other problem is it will only show the version of the artifact that's being loaded during the build (not that the other are not loaded but you get my point).

Any ways, removing unnecessary dependencies ore telling a dependency to exclude a particular jar will probably solve the problem, the fun of this game it to spot the correct one.


I know this post is not perfect guide on how to solve this problem but I hope it'll give you a better idea of what you're dealing whit and an idea on how to start solving it.



No hay comentarios:

Publicar un comentario