Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependencies vs dependency management for multiple projects

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

like image 477
Harry Avatar asked Jun 25 '13 14:06

Harry


People also ask

What is the difference between dependency and dependency management in Pom?

dependencyManagement is just a declaration, and it does not really add a dependency. The declared dependencies in this section must be later used by the dependencies tag. It is just the dependencies tag that causes real dependency to happen.

What is the use of dependency management in Maven?

Dependency management in Maven allows teams to manage dependencies for multi-module projects and applications. These can consist of hundreds or even thousands of modules. Using Maven can help teams define, create, and maintain reproducible builds.

What is the purpose of dependency management?

Dependency management - this allows project authors to directly specify the versions of artifacts to be used when they are encountered in transitive dependencies or in dependencies where no version has been specified.

How do I add a project as a dependency of another project Maven?

Right-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.


1 Answers

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.

like image 104
Manfred Moser Avatar answered Oct 29 '22 10:10

Manfred Moser