Maven dependencies vs dependency management for multiple projects
In dependencyManagement you declare dependency versions, exclusions and other things that let you manage them in place (e.g. a parent pom) for multiple projects.
In dependencies you then declare the actual usage/need of a dependency and if the dependency is managed in a parent pom you can do so without using a version and it will be inherited and therefore be consistant across your usages downstream of the the parent pom.
Same logic applies for pluginManagement and plugins by the way including plugin configuration.
Related videos on Youtube
Harry
Updated on September 14, 2022Comments
-
Harry over 1 year
Sorry to ask this again. Please let me know if I got this right?
We have a parent pom and multiple modules. Now if all children projects want to inherit the same jar files (for example spring), I can put them in in the parent project pom and need not include them in the child pom.
And if I put in dependencies under in the parent pom, they are not included in all the children projects, but I can include the ones I need (for example test) by adding them in without the need to specify a version.
Is this right or am I totally off? Hope I'm clear on my q.
All I need is a giant parent pom with all dependencies. The children should get some of the common dependencies automatically and the specific ones that each child needs.
Thanks
Harish
-
Harry almost 11 yearsThanks so much for your reply. So I will create <dependencyManagement> in the parent pom with versions and exclusions. Then I need to add <dependencies> in the parent pom that need to be inherited by all children and then create <dependencies> in the children for the ones that they alone need. The dependencies created under <dependencyManagement> will not be inherited by any of the projects. Is that right?
-
Harry almost 11 yearsStill not very clear: In the parent pom under <dependencyManagement> I have listed all the dependencies with exclusions, version, etc. Then under <dependencies> in the parent I have listed some dependencies that would be used for all projects (like logging). So the other dependencies under <dependencyManagement> will not be included in the children, right?
-
Manfred Moser almost 11 yearsDo not add dependencies in the parent. Just add them where they are actual dependencies. The depMgt will always be inherited. If you really need to manage a bunch of deps you can use the import scope but thats getting more complicated than necessary.