Skip to main content

How to create a Maven multi-module project in IntelliJ

When growing no of code lines or developers, increase the software complexity also. Sometimes it’s very difficult to identify the given class responsibility. If we will be able to modularization the project. It’ll be decreased the complexity.

Prerequisites

  1. Java
  2. Maven
  3. IntelliJ IDEA (my version is 15)

 

1. Create a new project.

2. Select “Maven”.

new project

 

3. Insert “GroupId” and “ArtifcatId”.

new project

 

4. Then give a project name.

new project

 

5. Now your project looks like this.

project

 

6. pom.xml

 

7. Now, we’re going to add the module. Here is the guide for maven module naming convention. We can divide modules based on responsibilities such as security, core service, api, ui etc.

add module

 

8. Let say, we need to add “core” module.

add module

 

9. Give module name.

add module

 

10. After adding no of modules. It looks like this.

modules

 

Now almost done. We’re going to add a dummy class.

11.  Click on the “core” module.

modules

 

12. We have to mark as a “Source root“.

mark as source root

 

13. Then add following package (com.company.core) and Java class (CoreService.java).

14. Now we’re going to use “core” service in the “api” module. Create a package (com.company.api) in the “api” module. Add a java class (APIService.class).

15. After that, we need to add “core” module into the “api” module. Open the pom.xml that related to “api” module. Add the “core” dependecy.

16. Then rebuild the whole project.

build the project

 

17. Then call core services inside api module.

GitHub:- maven-multi-module-source-code


1158total visits,9visits today

RSS
Follow by Email
Facebook
Facebook
Google+
http://mydevgeek.com/how-to-create-a-maven-multi-module-project-in-intellij
Twitter