Implementation of idea creating multi module Maven aggregation project

Time:2021-3-24

1. How to understand the inheritance and aggregation of maven

Maven multi module project is usually composed of a parent module and several sub modules, each module corresponds to a module pom.xml . They are related to each other through inheritance and aggregation (also known as multi module). Multi module is suitable for some large projects. Through reasonable module splitting, code reuse is realized, which is easy to maintain and manage.
Inheritance: similar to inheritance in Java, it is the parent pom.xml The declared version and the referenced jar can be directly called by the submodule without reference.
Aggregation: if the parent module contains multiple sub modules, it is aggregation. Multiple sub modules can be called, but pay attention to the relationship. Don’t rely on each other. The advantage of this is that it can be built with one command

be careful:

Groupid is the unique identifier of the project organization, which actually corresponds to the java package structure. Artifactid is the unique identifier of the project, and the name of the actual corresponding project is the name of the project root directory. Generally, groupid is divided into several segments. The first segment is the domain, the second segment is the company name, and the third segment is the project name.

2. Idea creates a multi module project

2.1 create parent module (empty Maven project)

pom.xml to configure
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-parent</artifactId> 
 <version>2.1.6.RELEASE</version> 
</parent> 
 
<groupId>cn.yskcoder.fire</groupId> 
<artifactId>fire</artifactId> 
<packaging>pom</packaging> 
<version>v1.0</version> 
 
 
<modules> 
 <module>fire-common</module> 
 <module>fire-dao</module> 
 <module>fire-service</module> 
 <module>fire-web</module> 
</modules> 
 
<properties> 
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
 <java.version>1.8</java.version> 
 <spring-boot.version>2.1.6.RELEASE</spring-boot.version> 
 
</properties>

2.2. Create a common module (Dao and service are the same as this operation)

pom.xml to configure
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<! -- module information -- > 
<packaging>jar</packaging> 
<name>fire-common</name> 
<artifactId>fire-common</artifactId> 
< description > fire general tool class module 
 
<! -- module dependency -- > 
<dependencies> 
 
</dependencies>

2.3. Create database access (DAO) module (paste only) pom.xml (code)

<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<! -- module information -- > 
<packaging>war</packaging> 
<name>fire-web</name> 
<artifactId>fire-web</artifactId> 
< description > fire web module < / description > 
 
<! -- module dependency -- > 
<dependencies> 
 <dependency> <groupId>cn.yskcoder.fire</groupId> 
 <artifactId>fire-service</artifactId> 
 <version>v1.0</version> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-web</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-aop</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-test</artifactId> 
 <scope>test</scope> 
 </dependency> 
</dependencies>


<build> 
 <plugins> 
  <plugin> 
   <groupId>org.apache.maven.plugins</groupId> 
   <artifactId>maven-compiler-plugin</artifactId> 
   <version>3.1</version> 
   <configuration> 
    <source>${java.version}</source> 
    <target>${java.version}</target> 
   </configuration> 
  </plugin>
 </plugins>
 <resources> 
  <resource> 
  <directory>src/main/webapp</directory> 
  <filtering>false</filtering> 
  </resource> 
  <resource> 
   <directory>src/main/resources</directory> 
   <filtering>true</filtering> 
  </resource> 
 </resources>
</build>

3. Idea package multi module project

clean package -Dmaven.test.skip=true

I will continue to update this project when I have time
https://github.com/yskcoder/Fire

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.