Aggregate engineering: Refers to Maven
engineering-based modular development. Its advantages are:
- The directory is clear and easy to manage
- Support separate development (team)
- Convenient and unified dependency version management
In practice, this is how I understand it (it may be wrong, but I think the mind is open, and it’s fine to understand what makes sense).
The project boss sent a task, and he did the following things first:
- The structure of the project is set up in advance and the dependency management
pom
in the file is specified - Each person is assigned the underlying tasks , such as: entity class, Mapper+ test, Service layer, Controller...
- Since each person's time limit is different, and they may be responsible for multiple projects at the same time, teamwork is likely to be carried out on a ladder.
OK, next, let's learn about aggregation engineering for the first two things.
step
New Construction
Create a new empty project and specify it maven
as a package management tool.
After entering the project, delete src
the directory, because this is a parent project, which src
is used as a source code directory, and the parent project does not edit code here, so delete it directly.
Edit pom file - unified dependency management
The mainstream is to use SpringBoot
development, so you can specify the parent of a parent directory:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.6.RELEASE</version>
</parent>
复制代码
In properties
the label, specify the version number that our project needs to rely on. This is mainly spring-boot-starter-parent
done in the form of reference. If you are interested, you can click to have a look spring-boot-dependencies
.
In order to introduce an integration project later, some basic packages are introduced first, and their version numbers are specified:
- mybatis-plus: data persistence layer framework
- knife4j: interface documentation framework
- jwt: jwt security authentication
- fastjson: json format conversion
<properties>
<java.version>1.8</java.version>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
<mysql.version>8.0.30</mysql.version>
<knife4j.version>3.0.3</knife4j.version>
<jwt.version>0.9.1</jwt.version>
<fastjson.version>2.0.21</fastjson.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
复制代码
The purpose of this is to first make sure that there is no conflict in the packages that this project depends on.
This is not enough. This is just to specify the version number, which is the same as defining a variable. In order to introduce the dependency configuration for subsequent projects, the version number will not be put in. We also need to write dependencyManagement
labels.
<dependencyManagement>
<dependencies>
<!--mybatis-plus 持久层-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<!--jjwt-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
复制代码
In this way, it is no longer necessary to specify the version number when subsequent submodules import this dependency .
New Module - Assign Tasks
Click as shown in the figure
Here is an example, the other steps are the same. The key point is to see clearly Parent
that what is written is the corresponding one in the parent project.artifactId
Verification: A blue down arrow is visible in the parent project:
This means that an independent submodule has been created under this project.
Then assign these modules from the low-down working order . Submodules can dependencies
be dependent by writing descriptions of other submodules (as follows), for example: service
layer dependency mapper
layer
<dependency>
<groupId>top.chengyunlai</groupId>
<artifactId>mapper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
复制代码