Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share dependencies among multiple POM files

Tags:

maven

maven-3

What is the best practice method of sharing multiple dependencies across Maven projects.

I can think of the following 2 possible approaches -

  1. Creating a parent POM file and using that same POM file in each project that is using the set of dependencies.

  2. Creating a new maven project with a POM file that contains the dependencies. Then referencing this project within all projects that require the common dependencies.

Are there any other approaches, which one should I use ?

like image 578
blue-sky Avatar asked Jan 25 '12 11:01

blue-sky


2 Answers

IMO it depends a bit on your exact use case.

Option 1 is certainly a good way to go but it can become more difficult/complex to manage if you already have a parent project and especially if you have several of those shared dependency sets (you might find yourself lost in a complex hierarchy of multiple parents). Another disadvantage of option 1 is that (AFAIK) it is not possible to exclude inherited dependencies so if your project extends the parent pom you have no choice but to inherit all the dependencies.

In that case option 2 is easier to manage, clearer and more flexible. Create a maven project of type POM and add a dependency to this where needed. With this solution it is possible to exclude certain dependencies from the POM project which again makes this solution more flexible.

like image 153
Stijn Geukens Avatar answered Oct 30 '22 01:10

Stijn Geukens


Option 1 works well - I'd suggest that.

like image 26
TrueDub Avatar answered Oct 29 '22 23:10

TrueDub