Maven-将pom的所有子模块作为依赖项包含在另一个模块中 [英] Maven - include all submodules of a pom as dependencies in another module

查看:1946
本文介绍了Maven-将pom的所有子模块作为依赖项包含在另一个模块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个设置如下的maven模块:

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

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

此子模块列表设置为随着时间的流逝而增长(大约20个列表).我们还有另一个模块,其中将包含a的所有子模块作为依赖项.有没有一种巧妙的方法来执行此操作,而不必手动使子模块列表与依赖项列表保持同步. IE.有没有办法将a和所有子模块都包含为依赖项?

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?

推荐答案

您在这里有几种选择:

  1. 没有变化.列出每个pom中的所有依赖项.但是,如果它们具有共同的父级,则可以在父级pom中使用dependencyManagement来设置不同依赖项的版本.在子poms中,您无需列出版本.请参阅来自Maven的示例"部分.这种方法的缺点是,您必须一遍又一遍地重新列出相同的依赖项.
  2. 创建一个列出所有共享依赖项的父pom.请参见此处的示例.不利之处在于,如果出于某些原因可能需要使用另一个父项目,则您限制所有希望利用此功能的项目使用一个父项目.
  3. 等待Maven mixins ,最后我听说仍未准备好.
  4. 重新考虑您的设计.对于项目来说,依赖这么多不同的模块和接口是否有意义?为了减少耦合,您可能想要创建一个这些新项目可以使用的界面使用.几个开源多模块项目(例如Apache Axis2)都遵循这种模式.一个模块包含您的20个依赖关系,并公开一个新模块可以调用的接口.新模块可以仅将一个主模块列出为依赖项,而将20个依赖项全部作为传递依赖项引入.
  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.

我认为选择#4可能是正确的,但是我对您的情况还不够熟悉.

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

这篇关于Maven-将pom的所有子模块作为依赖项包含在另一个模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆