🎨 #3844 【基础架构】将 httpclient4 依赖的 scope 从默认的 compile 改为 provided,以便让使用者可以更灵活地选择 HTTP 客户端实现

This commit is contained in:
buaazyl
2026-01-10 14:23:38 +08:00
committed by GitHub
parent e27325f580
commit 397bbe04c4
10 changed files with 66 additions and 6 deletions

View File

@@ -43,8 +43,8 @@
### 对现有项目
- **向后兼容**:不需要修改任何代码
- HttpClient 4.x 依然可用,项目同时包含两个版本的依赖
- 如果希望继续使用 HttpClient 4.x只需在配置中显式指定
- 如果希望继续使用 HttpClient 4.x只需在配置中显式指定pay 模块会自动包含 httpclient4 依赖(因为某些接口必须使用 httpclient4
其他模块mp、miniapp、cp、open、channel、qidian如果需要使用 httpclient4必须显式在项目中添加 httpclient4 依赖
## 迁移步骤
@@ -94,10 +94,10 @@ WxMpService wxMpService = new WxMpServiceHttpClientImpl();
A: 不会。项目保持完全向后兼容HttpClient 4.x 的所有实现都保持不变。
### Q: 我需要修改代码吗?
A: 大多数情况下不需要。如果希望继续使用 HttpClient 4.x只需在配置中指定 `http-client-type=HttpClient` 即可。
A: 大多数情况下不需要。如果希望继续使用 HttpClient 4.x只需在配置中指定 `http-client-type=HttpClient` ,并引入 HttpClient 4.x 依赖即可。
### Q: 我可以在同一个项目中同时使用两个版本吗?
A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如MP 模块使用 HttpClient 5.xMiniApp 模块默认使用 HttpClient 4.x但也可以按需配置为 HttpClient 5.x。
A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如MP 模块使用 HttpClient 5.xpay 模块部分接口仍使用 HttpClient 4.x但也可以按需配置为 HttpClient 5.x。
### Q: 如何排除不需要的依赖?
A: 如果只想使用一个版本,可以在 `pom.xml` 中排除另一个:
@@ -196,4 +196,4 @@ weixin-java-common/
-**推荐使用 HttpClient 5.x**:性能更好,功能更强
-**向后兼容**:可以继续使用 HttpClient 4.x
-**灵活配置**:支持多种 HTTP 客户端,按需选择
-**平滑迁移**:无需修改代码,仅需配置即可
-**平滑迁移**:无需修改代码,仅需配置,若不使用 HttpClient 5.x ,引入其他依赖即可

View File

@@ -136,7 +136,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<httpclient.version>4.5.13</httpclient.version>
<httpclient5.version>5.5</httpclient5.version>
<httpclient5.version>5.5.2</httpclient5.version>
<jetty.version>9.4.57.v20241219</jetty.version> <!-- 这个不能用10以上的版本不支持jdk8-->
</properties>
<dependencyManagement>

View File

@@ -29,6 +29,16 @@
<artifactId>jodd-http</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -34,6 +34,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
@@ -44,6 +45,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>

View File

@@ -30,6 +30,11 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -31,6 +31,16 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -31,6 +31,16 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -48,6 +48,16 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -34,6 +34,14 @@
<artifactId>jodd-util</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

View File

@@ -31,6 +31,11 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>