What is the best practice method of sharing multiple dependencies across Maven projects.
I can think of the following 2 possible approaches -
Creating a parent POM file and using that same POM file in each project that is using the set of dependencies.
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 ?
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.
Option 1 works well - I'd suggest that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With