Maven's aggregation project construction schematic

Aggregate engineering: Refers to Mavenengineering-based modular development. Its advantages are:

  1. The directory is clear and easy to manage
  2. Support separate development (team)
  3. 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:

  1. The structure of the project is set up in advance and the dependency managementpom in the file is specified
  2. Each person is assigned the underlying tasks , such as: entity class, Mapper+ test, Service layer, Controller...
  3. 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.

image.png

OK, next, let's learn about aggregation engineering for the first two things.

step

New Construction

Create a new empty project and specify it mavenas a package management tool.

image.png

After entering the project, delete srcthe directory, because this is a parent project, which srcis 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 SpringBootdevelopment, 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 propertiesthe label, specify the version number that our project needs to rely on. This is mainly spring-boot-starter-parentdone 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:

  1. mybatis-plus: data persistence layer framework
  2. knife4j: interface documentation framework
  3. jwt: jwt security authentication
  4. 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 dependencyManagementlabels.

<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

image.png

Here is an example, the other steps are the same. The key point is to see clearly Parentthat what is written is the corresponding one in the parent project.artifactId

image.png

Verification: A blue down arrow is visible in the parent project:

image.png

This means that an independent submodule has been created under this project.

Then assign these modules from the low-down working order . Submodules can dependenciesbe dependent by writing descriptions of other submodules (as follows), for example: servicelayer dependency mapperlayer

<dependency>
    <groupId>top.chengyunlai</groupId>
    <artifactId>mapper</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
复制代码

Guess you like

Origin juejin.im/post/7222257177187450936