使用Maven父级和模块 [英] Working with Maven parent and modules

查看:204
本文介绍了使用Maven父级和模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了神奇的Maven模块和父系统。

I have recently discovered the magical Maven modules and parent system.

我有几个应用程序,比方说A1,A2,A3(还有更多)。

I have a couple of apps, let's say A1, A2, A3(there are more).

我有几个依赖集,D1,D2,D3,D4(不是单一依赖,考虑整个框架,比如Spring及其组件)

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)

我的应用程序共享D4依赖集,所以我有一个包含它的基础pom,A1,A2,A3使用B1。

My apps share the D4 dependency set, so I have a base pom that contains it, B1 used by A1, A2, A3.

现在,棘手的部分:

A1取决于D1,D2。

A1 depends on D1, D2.

A2取决于在D2,D3。

A2 depends on D2, D3.

A3取决于D1,D3。

A3 depends on D1, D3.

如你所见,没有所有应用程序中使用的额外依赖集,因此我无法在基础POM中移动它。

As you can see, there is no extra dependency set used in all apps, so I can't move it in the base POM.

有没有什么好的方法可以管理这些依赖项?我有一个糟糕的一天,我必须更新应用程序的依赖项,我想以更简单的方式更改它。请记住,我有更多的应用程序,因此它不能是A1,A2,A3的特定答案。

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.

(旁注:如果你认为是OOP风格,我的应用程序是类,dependecies集是接口)

(Side note: If you think in an OOP style, my apps are classes, dependecies sets are interfaces)

推荐答案

我建议你:


  • 创建父项目(< packaging> pom< / packaging> )。

让你的模块扩展它(通过将< parent> your-parent< / parent> 添加到扩展它的项目中) 。

Make your modules extend it (by adding <parent>your-parent</parent> to the projects which extend it).

定义< dependeneciesManagement /> < pluginManagement /> 父母中的部分。

删除所有< version /> 来自扩展父项的项目的依赖项和插件的标签。

Remove all the <version/> tags for the dependencies and plugins from the projects which extend the parent.

您还可以为每种技术创建pom文件(在您的案件)。例如,您可以创建 spring-dependencies-pom ,其中包含< dependencyManagement /> 部分,仅定义您的春天依赖。然后在需要spring的模块中,只需使用< scope> import< / scope> spring-dependencies-pom C>。 (查看此处,了解<$ c $的说明c> import scope)。

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.

这篇关于使用Maven父级和模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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