简体   繁体   中英

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. Example the 3 components below make up 'System 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. 3. App 2 - a app/process with it's own code referencing the common lib.

My questions how do i setup Maven/Intelij to support this structure ... and is it a good structure to follow?

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.

Is this the correct way to go or how should i arrange Maven to support this structure?

Thanks in advance.

It sounds like a typical Maven multi-module setup should serve your needs. As for IntelliJ, just set it up in Maven and then import the maven pom into IntelliJ. It'll just work. You can just open the pom file as a project, and IntelliJ will set everything up for you correctly.

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. The artifactId should definitely be distinct, but not that distinct.
  3. Consider using Gradle instead if it's an option. It's the next logical step in build tools after Maven, and it'll vastly reduce your effort as the number of modules increases. Gradle/IntelliJ interaction is almost as good as 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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