Reputation: 5348
I have recently discovered the magical Maven modules and parent system.
I have a couple of apps, let's say A1, A2, A3(there are more).
I have a couple of dependencies sets, D1, D2, D3, D4(not a single dependency, think about an entire frameworks, like Spring with its components)
My apps share the D4 dependency set, so I have a base pom that contains it, B1 used by A1, A2, A3.
Now, the tricky part:
A1 depends on D1, D2.
A2 depends on D2, D3.
A3 depends on D1, D3.
As you can see, there is no extra dependency set used in all apps, so I can't move it in the base POM.
Is there any nice way of managing these dependencies? I am having a bad day when I have to update the dependencies for ever app, I want to change it in an easier way. Remember that I have more apps, so it must not be a particular answer for A1, A2, A3.
(Side note: If you think in an OOP style, my apps are classes, dependecies sets are interfaces)
Upvotes: 2
Views: 157
Reputation: 32567
I would recommend you:
Create a parent project (<packaging>pom</packaging>
).
Make your modules extend it (by adding <parent>your-parent</parent>
to the projects which extend it).
Define a <dependeneciesManagement/>
and <pluginManagement/>
section in the parent.
Remove all the <version/>
tags for the dependencies and plugins from the projects which extend the parent.
You can also create pom file per type of technology (in your case). For example, you can create spring-dependencies-pom
which contains a <dependencyManagement/>
section defining just your spring dependencies. Then in your module which needs spring, just add the spring-dependencies-pom
with <scope>import</scope>
. (Check here for explanations on the import
scope).
This will allow you to change things in one central place.
Upvotes: 4
Reputation: 5602
Use dependency management, as described in the links below, version management is delegated to parent and children modules can use them freely.
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html http://www.tutorialspoint.com/maven/maven_manage_dependencies.htm
Upvotes: 1
Reputation: 5127
I would think you could create modules D1, D2 etc. that have their dependencies listed in their POMs, but contain no Java code or other resources.
Then in e.g. module A1, you could add D1 & D2 as dependencies, and then all of THEIR dependencies would be included transitively.
Then you end up in a situation in which the dependencies making up D1 etc. can all be managed in the one place - that is, in D1's POM.
Is this what you're after?
Upvotes: 0