0

A module has a bad dependency which depends on multiple versions of the same library. This library is not used by any other dependency. If I just exclude the library to resolve version conflict then I need import the library obviously in every child module. This is not convenient and error prone. Is it possible to exclude specific version? I know exclude tag does not support version, but maybe there is a change.

Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49

1 Answers1

4

Use <dependencyManagement> to set the version of the library. This can be done in a parent pom. This version will overwrite all versions that are encountered in your dependency tree.

It will also satisfy the "dependency convergence" rule of the enforcer plugin.

Note that Maven will always load just one version of the same library - if it finds different versions, it uses a dependency resolution mechanism. It is a lot better, though, to resolve the conflict yourself with dependencyManagement.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • I tested on mvn 3.6.0 and it doesn't work. It is not working as I expected. Just putting excluded library into parent dependencyManagement section is not enough. It should be repeated in every child module. So no static support from maven. Just running test save my – Daniil Iaitskov Jan 31 '19 at 01:34
  • You do not need to repeat the dependencyManagement in the child modules. If you do it in the parent pom, it will be used by all children. The child modules, though, are able to overwrite the dependencyManagement by their own, or by declaring the dependency explicitly. You can analyse the situation by `mvn dependency:tree`. – J Fabian Meier Jan 31 '19 at 07:55