Is there a valid use case for having two different versions of the same artifact in the dependency management section of your POM?
I'm looking at a project whose root POM contains such an example. The project itself has multiple modules using different versions of this "duplicate dependency". Some of the modules thus have to specify the artifact's version explicitly among their dependencies so as to distinguish between the two.
If the POM files of the modules have to specify the version anyway, what is the reason for having the duplication in the parent's dependency management? The dependency would get looked up properly even if it was removed from dependency management, so why would you duplicate it there in the first place?
I'm just trying to figure out if this is good practice or if there's a better solution to such a situation.
Actually, if you are using Maven3+, you'll get a warning like this:
[WARNING]
[WARNING] Some problems were encountered while building the effective model for groupId:artifactId:jar:1.0-SNAPSHOT
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: junit:junit:jar -> version 3.8.1 vs 3.0 @ line 15, column 18
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Maven will pick up the first, so the second will never be used. Just remove it to prevent more confusion :)