Maven多模块优于简单依赖 [英] Maven Multi Module benefits over simple dependency

查看:131
本文介绍了Maven多模块优于简单依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven项目上有多年的经验,即使是多模块项目(使我讨厌 maven的多模块功能(因此免责声明现在已经完成)),即使我真的很喜欢Maven,但我无法获得明确的答案:

多模块Maven项目的典型用例是什么?与简单的依赖项和父pom相比,这种结构的附加价值是什么?

我已经看到了许多多模块项目的配置,但是通过创建一个简单的依赖库结构(作为交付品(甚至与父pom作为单独的交付品)来生活),显然可以解决所有这些问题:缺陷和配置),我还没有找到可以清楚地看到多模块结构的附加值的用例.

我总是发现这种结构带来了过度杀伤的复杂性,却没有真正的好处:我在哪里缺少某些东西? (说实话,我可以得到一些ear可以从这种结构中受益,但是除了那个特定的用例之外,还有其他实际用途和收益吗?)

解决方案

这是一个真实的案例.

我有一个多模块项目(对您来说,我没有看到任何复杂的项目.)最终结果是一个webapp,但是我有用于api,impl和webapp的不同模块.

创建项目12个月后,我发现必须使用从jar运行的独立流程与Amazon S3集成.我添加了一个依赖于api/impl的新模块,并在新模块中编写了集成代码.我使用组装插件(或类似的插件)创建了一个可运行的jar,现在我可以在tomcat中部署战争,并且可以在另一台服务器上部署进程.我的S3集成过程中没有Web类,并且Webapp中没有Amazon依赖项,但是我可以共享api和impl中的所有内容.

3个月后,我们决定创建一个REST Webapp.我们希望将其作为单独的应用程序而不是仅在现有Web应用程序中使用新的URL映射来完成.简单的.另外一个模块,另一个是通过maven构建而创建的webapp,没有特别的修改.业务逻辑可以轻松地在webapp和rest-webapp之间共享,我可以根据需要进行部署.

I have some years of experience with maven projects, even with multi modules ones (which has made me hate the multi modules feature of maven (so the disclaimer is now done)) and even if I really like maven there is something I cannot get a clear answer about :

What is a typical usecase of a multi module maven project ? What is the added value of such a structure compared to simple dependencies and parent pom ?

I have seen a lot of configuration of multi module projects but all of them could have clearly been addressed by creating a simple structure of dependency library living their own life as deliverables (even with a parent pom, as a separate deliverable : factorising depedencies and configuration) and I haven't found any usecase where I can clearly see an added value of the multi module structure.

I have always found that this kind of structure brings an overkilling complexity with no real benefit : where am I missing something ? (to be truly honest, I can get that some ear can benefit from this kind of structure but except from that particular usecase, any other real use and benefit ?)

解决方案

Here's a real life case.

I have a multi-module project (and to your rant... I haven't seen any complications with it.) The end result is a webapp but I have different modules for api, impl, and webapp.

12 months after creating the project I find that I have to integrate with Amazon S3 using a stand-alone process run from a jar. I add a new module which depends on api/impl and write my code for the integration in the new module. I use the assembly plugin (or something like it) to create a runnable jar and now I have a war I can deploy in tomcat and a process I can deploy on another server. I have no web classes in my S3 integration process and I have no Amazon dependencies in my webapp but I can share all the stuff in api and impl.

3 months after that we decide to create a REST webapp. We want to do it as a separate app instead of just new URL mappings in the existing webapp. Simple. One more module, another webapp created as the result of the maven build with no special tinkering. Business logic is shared easily between webapp and rest-webapp and I can deploy them as needed.

这篇关于Maven多模块优于简单依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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