A Maven aggregation project allows you to create multiple components (projects) in a Maven parent project. These multiple components can depend on each other to achieve component reuse.
1. Create a normal Maven project
Creation completed
2. Modify the pom.xm of the parent project and set the packaging method to pom.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.study</groupId>
<artifactId>Maven-study</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
The parent project is used to manage sub-projects and does not implement business, so the src directory can be selectively deleted.
3. Create Module
Select the parent project-right-click-New-Module, then select the project type you want to create
and enter the sub-project name (inherited from the parent project).
The module's pom will inherit the parent project's pom.
The parent project's pom will declare the child of the current parent project. Modules
generally only store pojo, dao and other reusable classes in common, and then call them in other modules.
4. Create two SpringBoot submodules
5. Modify the parent project pom file to inherit spring-boot-starter-parent, declare the sub-module, and add the dependencies that both projects need to use.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.study</groupId>
<artifactId>Maven-study</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>common</module>
<module>manager-system</module>
<module>user-system</module>
</modules>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
6. Inherit the parent project in the two child modules and delete the declared dependencies in the parent project
By introducing the common module into a sub-project, you can call the classes in the common. Before doing this, you need to compile and package the common module and
add dependencies in dependency management: dependencyManagement in the parent project, which means defining the default version of this dependency in the sub-project.