📝 Revise development instructions with Chinese translations
Some checks failed
Publish to Maven Central / build-and-publish (push) Has been cancelled

This commit is contained in:
Binary Wang
2025-10-23 11:00:01 +08:00
committed by GitHub
parent 98329b11da
commit b9b4f00438

View File

@@ -1,198 +1,202 @@
# WxJava - WeChat Java SDK Development Instructions # Copilot Instruction
请始终使用中文生成 Pull Request 的标题、描述和提交信息
WxJava is a comprehensive WeChat Java SDK supporting multiple WeChat platforms including Official Accounts (公众号), Mini Programs (小程序), WeChat Pay (微信支付), Enterprise WeChat (企业微信), Open Platform (开放平台), and Channel/Video (视频号). This is a Maven multi-module project with Spring Boot and Solon framework integrations.
**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the information here.** # WxJava - 微信 Java SDK 开发说明
## Working Effectively WxJava 是一个支持多种微信平台的完整 Java SDK包含公众号、小程序、微信支付、企业微信、开放平台、视频号、企点等多种功能模块。
### Prerequisites and Environment Setup **请始终优先参考本说明,只有在遇到与此内容不一致的意外信息时,才退而使用搜索或 bash 命令。**
- **Java Requirements**: JDK 8+ required (project uses Java 8 as minimum target)
- **Maven**: Maven 3.6+ recommended (Maven 3.9.11 validated)
- **IDE**: IntelliJ IDEA recommended (project optimized for IDEA)
### Bootstrap, Build, and Validate ## 高效开发指南
Execute these commands in sequence after cloning:
### 前置条件与环境准备
- **Java 要求**JDK 8+(项目最低目标为 Java 8
- **Maven**:推荐 Maven 3.6+(已验证 Maven 3.9.11
- **IDE**:推荐使用 IntelliJ IDEA项目针对 IDEA 优化)
### 引导、构建与校验
克隆仓库后按顺序执行以下命令:
```bash ```bash
# 1. Basic compilation (NEVER CANCEL - takes 4-5 minutes) # 1. 基础编译(请勿中断 - 约需 4-5 分钟)
mvn clean compile -DskipTests=true --no-transfer-progress mvn clean compile -DskipTests=true --no-transfer-progress
# Timeout: Set 8+ minutes. Actual time: ~4 minutes # 超时时间:建议设置 8 分钟以上。实际时间:约 4 分钟
# 2. Full package build (NEVER CANCEL - takes 2-3 minutes) # 2. 完整打包(请勿中断 - 约需 2-3 分钟)
mvn clean package -DskipTests=true --no-transfer-progress mvn clean package -DskipTests=true --no-transfer-progress
# Timeout: Set 5+ minutes. Actual time: ~2 minutes # 超时时间:建议设置 5 分钟以上。实际时间:约 2 分钟
# 3. Code quality validation (NEVER CANCEL - takes 45-60 seconds) # 3. 代码质量校验(请勿中断 - 约需 45-60 秒)
mvn checkstyle:check --no-transfer-progress mvn checkstyle:check --no-transfer-progress
# Timeout: Set 3+ minutes. Actual time: ~50 seconds # 超时时间:建议设置 3 分钟以上。实际时间:约 50 秒
``` ```
**CRITICAL TIMING NOTES:** 重要时间说明:
- **NEVER CANCEL** any Maven build command - 绝对不要中断任意 Maven 构建命令
- Compilation phase takes longest (~4 minutes) due to 34 modules - 编译阶段耗时最长(约 4 分钟),原因是项目包含 34 个模块
- Full builds are faster on subsequent runs due to incremental compilation - 后续构建会更快,因为存在增量编译
- Always use `--no-transfer-progress` to reduce log noise - 始终使用 `--no-transfer-progress` 以减少日志噪音
### Testing Structure ### 测试结构
- **Test Framework**: TestNG (not JUnit) - **测试框架**TestNG(非 JUnit
- **Test Files**: 298 test files across all modules - **测试文件**:共有 298 个测试文件
- **Default Behavior**: Tests are DISABLED by default in pom.xml (`<skip>true</skip>`) - **默认行为**pom.xml 中默认禁用测试(`<skip>true</skip>`
- **Test Configuration**: Tests require external WeChat API credentials via test-config.xml files - **测试配置**:测试需要通过 test-config.xml 提供真实的微信 API 凭据
- **DO NOT** attempt to run tests without proper WeChat API credentials as they will fail - **注意**:没有真实微信 API 凭据请不要尝试运行测试,测试将会失败
## Project Structure and Navigation ## 项目结构与导航
### Core SDK Modules (Main Development Areas) ### 核心 SDK 模块(主要开发区)
- `weixin-java-common/` - Common utilities and base classes (most important) - `weixin-java-common/` - 通用工具与基础类(最重要)
- `weixin-java-mp/` - WeChat Official Account SDK (公众号) - `weixin-java-mp/` - 公众号 SDK
- `weixin-java-pay/` - WeChat Pay SDK (微信支付) - `weixin-java-pay/` - 微信支付 SDK
- `weixin-java-miniapp/` - Mini Program SDK (小程序) - `weixin-java-miniapp/` - 小程序 SDK
- `weixin-java-cp/` - Enterprise WeChat SDK (企业微信) - `weixin-java-cp/` - 企业微信 SDK
- `weixin-java-open/` - Open Platform SDK (开放平台) - `weixin-java-open/` - 开放平台 SDK
- `weixin-java-channel/` - Channel/Video SDK (视频号) - `weixin-java-channel/` - 视频号 / Channel SDK
- `weixin-java-qidian/` - Qidian SDK (企点) - `weixin-java-qidian/` - 企点 SDK
### Framework Integration Modules ### 框架集成模块
- `spring-boot-starters/` - Spring Boot auto-configuration starters - `spring-boot-starters/` - Spring Boot 自动配置 starter
- `solon-plugins/` - Solon framework plugins - `solon-plugins/` - Solon 框架插件
- `weixin-graal/` - GraalVM native image support - `weixin-graal/` - GraalVM 本地镜像支持
### Configuration and Quality ### 配置与质量控制
- `quality-checks/google_checks.xml` - Checkstyle configuration - `quality-checks/google_checks.xml` - Checkstyle 配置
- `.editorconfig` - Code formatting rules (2 spaces = 1 tab) - `.editorconfig` - 代码格式规则2 个空格等于 1 个制表)
- `pom.xml` - Root Maven configuration - `pom.xml` - 根级 Maven 配置
## Development Workflow ## 开发工作流
### Making Code Changes ### 修改代码的流程
1. **Always build first** to establish clean baseline: 1. 修改前务必先构建以建立干净基线:
```bash ```bash
mvn clean compile --no-transfer-progress mvn clean compile --no-transfer-progress
``` ```
2. **Follow code style** (enforced by checkstyle): 2. 遵循代码风格(由 checkstyle 强制):
- Use 2 spaces for indentation (not tabs) - 缩进使用 2 个空格(不要用制表符)
- Follow Google Java Style Guide - 遵循 Google Java 风格指南
- Install EditorConfig plugin in your IDE - 在 IDE 中安装 EditorConfig 插件
3. **Validate changes incrementally**: 3. 增量验证修改:
```bash ```bash
# After each change: # 每次修改后运行:
mvn compile --no-transfer-progress mvn compile --no-transfer-progress
mvn checkstyle:check --no-transfer-progress mvn checkstyle:check --no-transfer-progress
``` ```
### Before Submitting Changes ### 提交修改前的必须校验
**ALWAYS run these validation steps in sequence:** 请务必按顺序完成以下校验步骤:
1. **Code Style Validation**: 1. 代码风格校验:
```bash ```bash
mvn checkstyle:check --no-transfer-progress mvn checkstyle:check --no-transfer-progress
# Must pass - takes ~50 seconds # 必须通过 - 约需 50 秒
``` ```
2. **Full Clean Build**: 2. 完整清理构建:
```bash ```bash
mvn clean package -DskipTests=true --no-transfer-progress mvn clean package -DskipTests=true --no-transfer-progress
# Must succeed - takes ~2 minutes # 必须成功 - 约需 2 分钟
``` ```
3. **Documentation**: Update javadoc for public methods and classes 3. 文档:为公共方法和类补充或更新 javadoc
4. **Contribution Guidelines**: Follow `CONTRIBUTING.md` - PRs must target `develop` branch 4. 贡献规范:遵循 `CONTRIBUTING.md`Pull Request 必须以 `develop` 分支为目标
## Module Dependencies and Build Order ## 模块依赖与构建顺序
### Core Module Dependencies (Build Order) ### 核心模块依赖(构建顺序)
1. `weixin-graal` (GraalVM support) 1. `weixin-graal`GraalVM 支持)
2. `weixin-java-common` (foundation for all other modules) 2. `weixin-java-common`(所有模块的基础)
3. Core SDK modules (mp, pay, miniapp, cp, open, channel, qidian) 3. 核心 SDK 模块mp、payminiapp、cp、openchannelqidian
4. Framework integrations (spring-boot-starters, solon-plugins) 4. 框架集成(spring-boot-starterssolon-plugins
### Key Relationship Patterns ### 主要关系模式
- All SDK modules depend on `weixin-java-common` - 所有 SDK 模块都依赖于 `weixin-java-common`
- Spring Boot starters depend on corresponding SDK modules - Spring Boot starters 依赖对应的 SDK 模块
- Solon plugins follow same pattern as Spring Boot starters - Solon 插件遵循与 Spring Boot starters 相同的依赖模式
- Each module has both single and multi-account configurations - 每个模块都有单账号与多账号配置支持
## Common Tasks and Commands ## 常见任务与命令
### Validate Specific Module ### 验证指定模块
```bash ```bash
# Build single module (replace 'weixin-java-mp' with target module): # 构建单个模块(将 'weixin-java-mp' 替换为目标模块):
cd weixin-java-mp cd weixin-java-mp
mvn clean compile --no-transfer-progress mvn clean compile --no-transfer-progress
``` ```
### Check Dependencies ### 检查依赖
```bash ```bash
# Analyze dependencies: # 分析依赖树:
mvn dependency:tree --no-transfer-progress mvn dependency:tree --no-transfer-progress
# Check for dependency updates: # 检查依赖更新:
./others/check-dependency-updates.sh ./others/check-dependency-updates.sh
``` ```
### Release and Publishing ### 发布与发布准备
```bash ```bash
# Version check: # 版本检查:
mvn versions:display-property-updates --no-transfer-progress mvn versions:display-property-updates --no-transfer-progress
# Deploy (requires credentials): # 部署(需要凭据):
mvn clean deploy -P release --no-transfer-progress mvn clean deploy -P release --no-transfer-progress
``` ```
## Important Files and Locations ## 重要文件与位置
### Configuration Files ### 配置文件
- `pom.xml` - Root Maven configuration with dependency management - `pom.xml` - 根级 Maven 配置与依赖管理
- `quality-checks/google_checks.xml` - Checkstyle rules - `quality-checks/google_checks.xml` - Checkstyle 规则
- `.editorconfig` - IDE formatting configuration - `.editorconfig` - IDE 格式化配置
- `.github/workflows/maven-publish.yml` - CI/CD pipeline - `.github/workflows/maven-publish.yml` - CI/CD 工作流
### Documentation ### 文档
- `README.md` - Project overview and usage (Chinese) - `README.md` - 项目概览与使用说明(中文)
- `CONTRIBUTING.md` - Development contribution guidelines - `CONTRIBUTING.md` - 贡献指南
- `demo.md` - Links to demo projects and examples - `demo.md` - 示例项目与演示链接
- Each module has dedicated documentation and examples - 每个模块均有单独的文档与示例
### Test Resources ### 测试资源
- `*/src/test/resources/test-config.sample.xml` - Template for test configuration - `*/src/test/resources/test-config.sample.xml` - 测试配置模板
- Tests require real WeChat API credentials to run - 测试运行需要真实的微信 API 凭据
## SDK Usage Patterns ## SDK 使用模式
### Maven Dependency Usage ### Maven 依赖示例
```xml ```xml
<dependency> <dependency>
<groupId>com.github.binarywang</groupId> <groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId> <!-- or other modules --> <artifactId>weixin-java-mp</artifactId> <!-- 或其他模块 -->
<version>4.7.0</version> <version>4.7.0</version>
</dependency> </dependency>
``` ```
### Common Development Areas ### 常见开发区域
- **API Client Implementation**: Located in `*/service/impl/` directories - **API 客户端实现**:位于 `*/service/impl/` 目录
- **Model Classes**: Located in `*/bean/` directories - **模型类**:位于 `*/bean/` 目录
- **Configuration**: Located in `*/config/` directories - **配置**:位于 `*/config/` 目录
- **Utilities**: Located in `*/util/` directories in weixin-java-common - **工具类**:位于 `weixin-java-common` 的 `*/util/` 目录
## Troubleshooting ## 故障排查
### Build Issues ### 构建问题
- **OutOfMemoryError**: Increase Maven memory: `export MAVEN_OPTS="-Xmx2g"` - **OutOfMemoryError**:增加 Maven 内存:`export MAVEN_OPTS="-Xmx2g"`
- **Compilation Failures**: Usually dependency issues - run `mvn clean` first - **编译失败**:通常为依赖问题 - 先执行 `mvn clean`
- **Checkstyle Failures**: Check `.editorconfig` settings in IDE - **Checkstyle 失败**:检查 IDE 的 `.editorconfig` 设置
### Common Gotchas ### 常见陷阱
- **Tests Always Skip**: This is normal - tests require WeChat API credentials - **测试默认跳过**:这是正常现象 — 测试需要微信 API 凭据
- **Multi-Module Changes**: Always build from root, not individual modules - **多模块变更**:总是在仓库根目录构建,而不是单独模块
- **Branch Target**: PRs must target `develop` branch, not `master`/`release` - **分支目标**Pull Request 必须以 `develop` 分支为目标,而不是 `master``release`
## Performance Notes ## 性能说明
- **First Build**: Takes 4-5 minutes due to dependency downloads - **首次构建**:由于依赖下载,耗时 4-5 分钟
- **Incremental Builds**: Much faster (~30-60 seconds) - **增量构建**:通常更快(约 30-60 秒)
- **Checkstyle**: Runs quickly (~50 seconds) and should be run frequently - **Checkstyle**:运行迅速(约 50 秒),应当经常运行
- **IDE Performance**: Project uses Lombok - ensure annotation processing is enabled - **IDE 性能**:项目使用 Lombok请确保启用注解处理
Remember: This is a SDK library project, not a runnable application. Changes should focus on API functionality, not application behavior. 注意:本项目为 SDK 库项目,而非可运行应用。修改应以 API 功能为主,不要改动应用级行为。