Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - include all submodules of a pom as dependencies in another module

Tags:

maven

We have a maven module that is set up as so:

a (parent)
  -> b (submodule)
  -> c (submodule)
  -> d (submodule)

This list of submodules is set to grow as time goes on (to a list of 20 or so). We have another module that will include as dependencies all submodules of a. Is there a neat way of doing this, rather than having to manually keep the submodule list in sync with the dependencies list. I.e. is there any way of including a and all submodules as a dependency?

like image 657
smauel Avatar asked Oct 21 '11 11:10

smauel


1 Answers

You have a few choices here:

  1. No change. List all dependencies in each pom. However, if they have a common parent, you can use dependencyManagement in the parent pom to set the versions for the different dependencies. In the child poms, you do not need to list the version. See this section from Maven By Example. A downside of this approach is that you have to re-list the same dependencies over and over.
  2. Create a parent pom which lists all shared dependencies. See an example here. A downside here is you are restricting all projects that want to take advantage of this to use a parent project when they may need to use another parent project for some reason.
  3. Wait for Maven mixins, which last I heard were still not ready.
  4. Rethink your design. Does it make sense for projects to depend on so many different modules and interfaces? To reduce coupling, you may want to create one interface that these new projects can use. Several open source multi-module projects, such as Apache Axis2, follow this pattern. One module contains your 20 dependencies and exposes an interface which the new modules can call. The new modules can just list that one main module as a dependency and all of the 20 dependencies are pulled in as transitive dependencies.

I think choice #4 is probably right, but I am not familiar enough with your situation.

like image 116
BennyMcBenBen Avatar answered Oct 11 '22 14:10

BennyMcBenBen