简体   繁体   English

我应该如何使用Maven和Intelij构建一个多组件Java项目?

[英]How should i structure a multi component Java project using Maven and Intelij?

my java se project/system consists of multiple components like below where there can be many shared libs and many applications/ running processes. 我的java se项目/系统由下面的多个组件组成,其中可以有许多共享库和许多应用程序/运行进程。 Example the 3 components below make up 'System 1'. 示例下面的3个组件组成'系统1'。

System 1: 1. Common lib - for our shared code 2. App 1 - a app/process with it's own code referencing the common lib. 系统1:1。通用库 - 用于我们的共享代码2.应用程序1 - 一个应用程序/进程,它自己的代码引用公共库。 3. App 2 - a app/process with it's own code referencing the common lib. 3.应用程序2 - 一个应用程序/进程,它自己的代码引用了公共库。

My questions how do i setup Maven/Intelij to support this structure ... and is it a good structure to follow? 我的问题是如何设置Maven / Intelij来支持这种结构......它是一个很好的结构吗?

At present I have the groupId as 'com.MyCompany.System1' and the Mavan modules for the components with artifactIds as 'com-MyCompany-System1-common' etc. 目前我将groupId作为'com.MyCompany.System1',将具有artifactIds的组件的Mavan模块作为'com-MyCompany-System1-common'等​​。

Is this the correct way to go or how should i arrange Maven to support this structure? 这是正确的方法,我应该如何安排Maven支持这种结构?

Thanks in advance. 提前致谢。

It sounds like a typical Maven multi-module setup should serve your needs. 听起来像典型的Maven多模块设置应该满足您的需求。 As for IntelliJ, just set it up in Maven and then import the maven pom into IntelliJ. 至于IntelliJ,只需在Maven中设置它,然后将maven pom导入IntelliJ。 It'll just work. 它会起作用。 You can just open the pom file as a project, and IntelliJ will set everything up for you correctly. 您可以将pom文件作为项目打开,IntelliJ将为您正确设置所有内容。

Advice: 建议:

  1. Even if it feels like more work up front, the more you can break up your project into cleanly-defined modules, the happier you'll be in the end. 即使感觉前期工作更多,您将项目分解为清晰定义的模块的次数越多,您最终会感到更快乐。
  2. I wouldn't repeat the groupId in the artifactId. 我不会在artifactId中重复groupId。 The artifactId should definitely be distinct, but not that distinct. artifactId肯定应该是不同的,但不是那么明显。
  3. Consider using Gradle instead if it's an option. 如果它是一个选项,请考虑使用Gradle It's the next logical step in build tools after Maven, and it'll vastly reduce your effort as the number of modules increases. 这是Maven之后构建工具的下一个合乎逻辑的步骤,随着模块数量的增加,它将大大减少您的工作量。 Gradle/IntelliJ interaction is almost as good as Maven/IntelliJ. Gradle / IntelliJ交互几乎与Maven / IntelliJ一样好。 It's slightly more work, but the tradeoff is worth it. 这稍微多一些工作,但权衡是值得的。

Source: I have a mix of >100 Maven and Gradle modules spread across >30 source code repos which I've been building and working in with IntelliJ for 3 years. 资料来源:我有超过100个Maven和Gradle模块的混合,分布在30多个源代码回购中,我用IntelliJ工作了3年。

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

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