What is the point of an exclusion of a dependency's dependency and re-declaring it?

149 Views Asked by At

I've noticed some pattern in projects's poms. There is a dependency graph like this: your Project A -> some other Project B -> B's dependency Project C. Project B is declared as a dependency in A's pom and B's dependency C excluded from B and re-declared as a direct dependency of project A. What is the point of this exclusion if Maven docs openly says it takes the "nearest" dependency, so if you declare it directly then Maven uses that version instead any of transitive ones?

1

There are 1 best solutions below

1
On

You normally do this to change the version or scope of the dependency. So you may exclude dependency to C from dependency to B, which leaves you without dependency to C. Now you add a direct dependency to C in A, with another version.

The documentation is still right, every artifact should declare what it directly needs. But in cases of conflicts the above pattern is the rescue.