一:项目架构
二.父项目pom.xml
<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/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.dmdd</groupId><artifactId>GeneralCode</artifactId><packaging>pom</packaging><version>0.0.1</version><modules><module>api</module></modules><properties><project.encoding>UTF-8</project.encoding><maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version><maven-resources-plugin.version>3.1.0</maven-resources-plugin.version><java.version>1.8</java.version><!-- 核心依赖 --><spring-boot.version>2.7.7</spring-boot.version><!-- 次要依赖 --><hutool-version>5.8.16</hutool-version><mybatis-spring-boot-starter.version>2.3.0</mybatis-spring-boot-starter.version><mybatis-plus-version>3.4.2</mybatis-plus-version><pagehelper-spring-boot-starter.version>1.4.3</pagehelper-spring-boot-starter.version><orika.version>1.5.4</orika.version><jsoup.version>1.13.1</jsoup.version><orika.version>1.5.4</orika.version><captcha.version>1.2.5</captcha.version><knife4j.version>4.1.0</knife4j.version><springdoc.version>1.6.9</springdoc.version><elasticsearch.version>7.17.5</elasticsearch.version><minio.version>8.2.2</minio.version><rocketmq-springboot.version>2.2.2</rocketmq-springboot.version><weixin.version>4.0.0</weixin.version><spring-javaformat.version>0.0.22</spring-javaformat.version><junit.version>4.13.1</junit.version><lombok.version>1.18.26</lombok.version><jwt.version>0.10.7</jwt.version><commons-pool2.version>2.8.0</commons-pool2.version><druid.version>1.2.5</druid.version><kaptcha.version>2.3.2</kaptcha.version><jwt.version>0.10.7</jwt.version><snakeyaml>1.27</snakeyaml><classfinal.version>1.2.1</classfinal.version></properties><dependencyManagement>
<dependencies>
<!-- 核心依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency><!-- 次要依赖 --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-bom</artifactId><version>${hutool-version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>${mybatis-spring-boot-starter.version}</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>${mybatis-plus-version}</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><version>${mybatis-plus-version}</version></dependency><!-- lombok用于实体类lsf4j--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency><!-- <dependency>-->
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
<!-- <artifactId>mssql-jdbc</artifactId>-->
<!-- <version>9.2.1.jre8</version>-->
<!-- </dependency>-->
<!--旧版sqlserver垃圾依赖-->
<!-- <dependency>-->
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
<!-- <artifactId>sqljdbc4</artifactId>-->
<!-- <version>4.0</version>-->
<!-- </dependency>--><!-- 解决复合主键 --><dependency><groupId>com.github.jeffreyning</groupId><artifactId>mybatisplus-plus</artifactId><version>1.5.1-RELEASE</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.6.1</version></dependency><!--连接池依赖-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<!-- <version>${druid.version}</version>-->
<!-- </dependency>--></dependencies></dependencyManagement><dependencies>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-configuration-processor</artifactId>-->
<!-- <optional>true</optional>-->
<!-- </dependency>--></dependencies><build><finalName>${project.name}</finalName><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement><plugins><plugin><groupId>io.spring.javaformat</groupId><artifactId>spring-javaformat-maven-plugin</artifactId><version>${spring-javaformat.version}</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.encoding}</encoding></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>${maven-resources-plugin.version}</version><configuration><encoding>${project.encoding}</encoding></configuration></plugin></plugins><resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource></resources></build>
</project>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-configuration-processor</artifactId>-->
<!-- <optional>true</optional>-->
<!-- </dependency>--> 这个依赖有什么用
这个依赖是用来支持Spring Boot的配置属性自动补全和提示的。它会生成一个用于IDE的元数据文件,用于提供配置属性的提示和文档。这样,在编写配置文件时,可以更方便地查看和使用Spring Boot的配置属性,并获得更好的开发体验。
<properties>
<spring-boot.version>2.7.7</spring-boot.version>
</properties>
填写依赖的版本号,方便依赖的版本管理,避免依赖冲突
就像定义常量,依赖的版本就引用定义好的常量
<dependencyManagement>
<dependencies>
。。。。
</dependencies>
<dependencyManagement>
此中的依赖不会被继承,子模块引入其中的依赖不需要指定版本
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>在<dependencyManagement> 外面的依赖可以被继承到
二.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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.dmdd</groupId><artifactId>GeneralCode</artifactId><version>0.0.1</version></parent><artifactId>common</artifactId><version>0.0.1</version><name>common</name><description>通用模块</description><dependencies>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter</artifactId>-->
<!-- </dependency>--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 该依赖具有自动填充createTime updateTime功能--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency><!--导入继承的父模块的lombok依赖--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId></dependency><!--配置动态数据源 需要父项目具有该依赖才可以使用,否则会报错--><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId></dependency><!--代码生成器依赖-->
<!-- <dependency>-->
<!-- <groupId>org.freemarker</groupId>-->
<!-- <artifactId>freemarker</artifactId>-->
<!-- <version>2.3.28</version>-->
<!-- </dependency>--></dependencies><build><plugins><!-- 资源文件拷贝插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><configuration><encoding>UTF-8</encoding></configuration></plugin></plugins></build></project>
三.api模块依赖
<?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"><modelVersion>4.0.0</modelVersion><parent><groupId>com.dmdd</groupId><artifactId>GeneralCode</artifactId><version>0.0.1</version></parent><artifactId>api</artifactId><version>0.0.1</version><name>api</name><description>接口模块</description><dependencies>
<!-- 该模块内部的依赖和内容会继承到此模块--><dependency><groupId>com.dmdd</groupId><artifactId>common</artifactId><version>0.0.1</version></dependency><dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>1.27</version></dependency><!-- junit --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot</artifactId>-->
<!-- </dependency>--><!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-autoconfigure</artifactId>-->
<!-- </dependency>--><!-- 代码生成器需要这个--><dependency><groupId>com.microsoft.sqlserver</groupId><artifactId>mssql-jdbc</artifactId><version>9.2.1.jre8</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
<parent>
<groupId>com.dmdd</groupId>
<artifactId>GeneralCode</artifactId>
<version>0.0.1</version>
</parent>继承了父模块 父模块中<dependencyManagement>的依赖不会被继承
<!-- 该模块内部的依赖和内容会继承到此模块-->
<dependency>
<groupId>com.dmdd</groupId>
<artifactId>common</artifactId>
<version>0.0.1</version>
</dependency>引用了common模块
四.查看依赖树
api模块中,common模块的依赖全部继承了, 父项目的依赖只继承了不在<dependencyManagement>里的依赖