1
0
mirror of synced 2026-05-22 14:43:15 +00:00

refactor: 优化模块依赖关系

This commit is contained in:
click33
2026-02-28 03:24:24 +08:00
parent 6a96d2fabd
commit 22e9ee80d0
7 changed files with 81 additions and 106 deletions
+41
View File
@@ -0,0 +1,41 @@
## 未完成目标:
### 1、尝试将所有 `<properties>` 依赖版本号定义在同一个 pom.xml 里。 **[❌失败]**
**尝试1:将所有 `<properties>` 定义在 `sa-token-dependencies` 里:**
结果: 无法在 `sa-token-spring-boot2/3/4-dependencies` 中引用这些 `<properties>`,因为 `<dependencyManagement> <dependencies> <scope>import</scope>` 只会导入目标的 `<dependencyManagement>` 版本号定义,不会导入目标的 `<properties>` 属性。
`<properties>` 只会在 父子结构中向下传递,不会在 `<dependencyManagement> <dependencies> <scope>import</scope>` 中传递。
**尝试2:将所有 `<properties>` 定义在 `sa-token-parent` 里:**
结果:在 `sa-token-dependencies` 里无法引用这些 `<properties>`,因为 `sa-token-parent` 不是 `sa-token-dependencies` 的父模块。
`sa-token-parent` 定义为 `sa-token-dependencies` 的父模块行吗?
不行,因为在 `sa-token-parent` 通过 `<dependencyManagement> <dependencies> <scope>import</scope>` 导入了 `sa-token-dependencies`,如果再把 `sa-token-parent` 定义为 `sa-token-dependencies` 的父模块,会造成循环依赖。
执行 `mvn package` 打包时,maven 会直接报错:
```
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] The dependencies of type=pom and with scope=import form a cycle: cn.dev33:sa-token-parent:1.44.0 -> cn.dev33:sa-token-basic-dependencies:1.44.0 -> cn.dev33:sa-token-basic-dependencies:1.44.0 @ cn.dev33:sa-token-basic-dependencies:1.44.0
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project cn.dev33:sa-token-parent:1.44.0 (E:\work\project-yun\sa-token\pom.xml) has 1 error
[ERROR] The dependencies of type=pom and with scope=import form a cycle: cn.dev33:sa-token-parent:1.44.0 -> cn.dev33:sa-token-basic-dependencies:1.44.0 -> cn.dev33:sa-token-basic-dependencies:1.44.0 @ cn.dev33:sa-token-basic-dependencies:1.44.0
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
```
+2 -2
View File
@@ -109,7 +109,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version> <version>3.12.0</version>
<configuration> <configuration>
<!-- 统一生成聚合文档,解决 mvn package 时控制台发出 javadoc 警告的问题 --> <!-- 统一生成聚合文档,解决 mvn package 时控制台发出 javadoc 警告的问题 -->
<aggregate>true</aggregate> <aggregate>true</aggregate>
@@ -132,7 +132,7 @@
<goal>jar</goal> <goal>jar</goal>
</goals> </goals>
<configuration> <configuration>
<additionalparam>-Xdoclint:none</additionalparam> <doclint>none</doclint>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
+7 -8
View File
@@ -4,6 +4,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
<relativePath/>
</parent>
<groupId>cn.dev33</groupId> <groupId>cn.dev33</groupId>
<artifactId>sa-token-bom</artifactId> <artifactId>sa-token-bom</artifactId>
<version>${revision}</version> <version>${revision}</version>
@@ -264,14 +271,6 @@
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<!-- 父仓库 -->
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
<relativePath/>
</parent>
<!-- 项目构建 --> <!-- 项目构建 -->
<build> <build>
<plugins> <plugins>
+9 -93
View File
@@ -4,16 +4,20 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.dev33</groupId> <parent>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-bom</artifactId>
<version>${revision}</version>
<!-- 寻址 -->
<relativePath>../sa-token-bom/pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
<artifactId>sa-token-dependencies</artifactId> <artifactId>sa-token-dependencies</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>sa-token-dependencies</name> <name>sa-token-dependencies</name>
<description>Sa-Token Dependencies</description> <description>Sa-Token Dependencies</description>
<properties> <properties>
<revision>1.44.0</revision>
<!-- 第三方依赖版本号 --> <!-- 第三方依赖版本号 -->
<jackson-databind.version>2.13.4.1</jackson-databind.version> <jackson-databind.version>2.13.4.1</jackson-databind.version>
<jackson-datatype-jsr310.version>2.11.2</jackson-datatype-jsr310.version> <jackson-datatype-jsr310.version>2.11.2</jackson-datatype-jsr310.version>
@@ -250,96 +254,8 @@
<version>${okhttps.version}</version> <version>${okhttps.version}</version>
</dependency> </dependency>
<!-- sa-token 自身依赖 -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-bom</artifactId>
<version>${revision}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<!-- 父仓库:不能使用 sa-token-parent,因其 dependencyManagement 会 import 本模块,形成循环依赖 -->
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
<relativePath/>
</parent>
<!-- 项目构建:因无法继承 sa-token-parent,此处需单独配置 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 统一版本号管理 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.7</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>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project> </project>
+1 -1
View File
@@ -14,7 +14,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<artifactId>sa-token-special-dependencies</artifactId> <artifactId>sa-token-special-dependencies</artifactId>
<name>sa-token-special-dependencies</name> <name>sa-token-special-dependencies</name>
<description>Sa-Token Special Dependencies - 聚合 Spring Boot 各版本依赖</description> <description>Sa-Token Special Dependencies</description>
<modules> <modules>
<module>sa-token-spring-boot2-dependencies</module> <module>sa-token-spring-boot2-dependencies</module>
@@ -147,3 +147,10 @@ public class SaReactorFilter implements SaFilter, WebFilter {
return chain.filter(exchange); return chain.filter(exchange);
} }
} }
/*
* 三种 Filter
* WebFilter Spring WebFlux 的过滤器,用于拦截 Web 请求
* GlobalFilter Spring Cloud Gateway 的全局过滤器,用于拦截 Gateway 请求
* GatewayFilter Spring Cloud Gateway 的局部过滤器,用于拦截 Gateway 请求
*/
+14 -2
View File
@@ -36,18 +36,30 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<version>2.5.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- config --> <!-- config -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<version>2.5.12</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot2-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>
<!-- 单元测试报告生成 --> <!-- 单元测试报告生成 -->