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

前端 未结 3 1260
忘掉有多难
忘掉有多难 2020-12-20 12:19

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

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

This list of subm

3条回答
  •  遥遥无期
    2020-12-20 13:05

    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.

提交回复
热议问题