简体   繁体   English

无法理解maven模块和父项目

[英]Trouble understanding maven modules and parent projects

I am trying to figure out how to structure my project for Maven, and I've become a little confused. 我想弄清楚如何为Maven构建我的项目,我变得有点困惑。

If I have a Project A, that can be distributed and used on its own, but then I have Project B (which can also be distributed on its own) which depends on Project A and sort of 'builds off' of Project A, should is be a module of ProjectA ? 如果我有一个项目A,可以单独分发和使用,但是我有项目B(也可以单独分发),这取决于项目A和项目A的“建立”,应该是ProjectA的一个模块? Then Say I have project C, which depends on project B, should that be a module of project B? 那么说我有项目C,它取决于项目B,应该是项目B的模块吗?

I guess I'm confused about how a multi-module project works. 我想我对多模块项目的工作原理感到困惑。

Thanks. 谢谢。

如果您不想寻找简短的描述,那么我建议您通过示例查看Maven的第7章: http//books.sonatype.com/mvnex-book/pdf/mvnex-pdf.pdf

In Maven you can't have cycle dependencies. 在Maven中,您不能拥有循环依赖性。 So in my opinion it would be better to create modules that will not depend on each other (or only on project API) and one that will have dependencies from all others. 因此,在我看来,创建不依赖于彼此(或仅在项目API上)的模块以及将具有来自所有其他模块的依赖项的模块会更好。 You need logically structurize them, every module must have some purpose. 您需要逻辑结构化它们,每个模块都必须有一些目的。

For example, module A will have your project API, module B will contain project core (and have dependency on A), module C will have some other purpose, some independent classes that you can use (and have dependencу on A), module D will have other functionality (and have dependency on A) and so on. 例如,模块A将包含项目API,模块B将包含项目核心(并且依赖于A),模块C将具有其他目的,一些可以使用的独立类(并且依赖于A),模块D将具有其他功能(并依赖于A)等。 Then, you can create moduleE, that will have dependencies on BC, D and will use functionality from these projects, will contain user interface and will be the main one. 然后,你可以创建moduleE,它将依赖于BC,D并将使用这些项目的功能,将包含用户界面并将成为主要的一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM