父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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <groupId>com.backend</groupId> <artifactId>scaffold</artifactId> <!--使用revision标签来关联统一版本号--> <version>${revision}</version> <name>scaffold</name> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> </parent> <modules> <module>gateway</module> <module>common</module> </modules> <properties> <!--使用revision标签定义项目版本--> <revision>0.0.1-SNAPSHOT</revision> </properties> <!--父pom定义的依赖会被子模块依赖 所以父pom中定义所有子模块需要依赖的jar包--> <dependencies> </dependencies> <!--父pom定义的依赖管理会约束子模块相关jar包的依赖版本,此处定义一些依赖但并不会被所有子模块自动依赖 子模块根据需要自动引入所需依赖的坐标--> <dependencyManagement> </dependencyManagement> <build> <plugins> <plugin> <!--该插件用于install/deploy时替换版本号,服务revision标签的使用--> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.1.0</version> <configuration> <updatePomFile>true</updatePomFile> <flattenMode>resolveCiFriendliesOnly</flattenMode> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> <execution> <id>flatten.clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> </plugins> </build></project>
子pom—common
<?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>
<artifactId>common</artifactId>
<packaging>jar</packaging>
<parent>
<artifactId>scaffold</artifactId>
<groupId>com.backend</groupId>
<version>${revision}</version>
</parent>
<dependencies>
</dependencies>
</project>
子pom-gateway(gateway模块依赖common模块)
<?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>
<artifactId>gateway</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.backend</groupId>
<artifactId>scaffold</artifactId>
<version>${revision}</version>
</parent>
<dependencies>
<dependency>
<groupId>com.backend</groupId>
<artifactId>common</artifactId>
<!--使用${project.version}标签来引入common模块-->
<version>${project.version}</version>
</dependency>
</dependencies>
</project>