|
| 1 | +# WxJava - WeChat Java SDK Development Instructions |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +**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.** |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Prerequisites and Environment Setup |
| 10 | +- **Java Requirements**: JDK 8+ required (project uses Java 8 as minimum target) |
| 11 | +- **Maven**: Maven 3.6+ recommended (Maven 3.9.11 validated) |
| 12 | +- **IDE**: IntelliJ IDEA recommended (project optimized for IDEA) |
| 13 | + |
| 14 | +### Bootstrap, Build, and Validate |
| 15 | +Execute these commands in sequence after cloning: |
| 16 | + |
| 17 | +```bash |
| 18 | +# 1. Basic compilation (NEVER CANCEL - takes 4-5 minutes) |
| 19 | +mvn clean compile -DskipTests=true --no-transfer-progress |
| 20 | +# Timeout: Set 8+ minutes. Actual time: ~4 minutes |
| 21 | + |
| 22 | +# 2. Full package build (NEVER CANCEL - takes 2-3 minutes) |
| 23 | +mvn clean package -DskipTests=true --no-transfer-progress |
| 24 | +# Timeout: Set 5+ minutes. Actual time: ~2 minutes |
| 25 | + |
| 26 | +# 3. Code quality validation (NEVER CANCEL - takes 45-60 seconds) |
| 27 | +mvn checkstyle:check --no-transfer-progress |
| 28 | +# Timeout: Set 3+ minutes. Actual time: ~50 seconds |
| 29 | +``` |
| 30 | + |
| 31 | +**CRITICAL TIMING NOTES:** |
| 32 | +- **NEVER CANCEL** any Maven build command |
| 33 | +- Compilation phase takes longest (~4 minutes) due to 34 modules |
| 34 | +- Full builds are faster on subsequent runs due to incremental compilation |
| 35 | +- Always use `--no-transfer-progress` to reduce log noise |
| 36 | + |
| 37 | +### Testing Structure |
| 38 | +- **Test Framework**: TestNG (not JUnit) |
| 39 | +- **Test Files**: 298 test files across all modules |
| 40 | +- **Default Behavior**: Tests are DISABLED by default in pom.xml (`<skip>true</skip>`) |
| 41 | +- **Test Configuration**: Tests require external WeChat API credentials via test-config.xml files |
| 42 | +- **DO NOT** attempt to run tests without proper WeChat API credentials as they will fail |
| 43 | + |
| 44 | +## Project Structure and Navigation |
| 45 | + |
| 46 | +### Core SDK Modules (Main Development Areas) |
| 47 | +- `weixin-java-common/` - Common utilities and base classes (most important) |
| 48 | +- `weixin-java-mp/` - WeChat Official Account SDK (公众号) |
| 49 | +- `weixin-java-pay/` - WeChat Pay SDK (微信支付) |
| 50 | +- `weixin-java-miniapp/` - Mini Program SDK (小程序) |
| 51 | +- `weixin-java-cp/` - Enterprise WeChat SDK (企业微信) |
| 52 | +- `weixin-java-open/` - Open Platform SDK (开放平台) |
| 53 | +- `weixin-java-channel/` - Channel/Video SDK (视频号) |
| 54 | +- `weixin-java-qidian/` - Qidian SDK (企点) |
| 55 | + |
| 56 | +### Framework Integration Modules |
| 57 | +- `spring-boot-starters/` - Spring Boot auto-configuration starters |
| 58 | +- `solon-plugins/` - Solon framework plugins |
| 59 | +- `weixin-graal/` - GraalVM native image support |
| 60 | + |
| 61 | +### Configuration and Quality |
| 62 | +- `quality-checks/google_checks.xml` - Checkstyle configuration |
| 63 | +- `.editorconfig` - Code formatting rules (2 spaces = 1 tab) |
| 64 | +- `pom.xml` - Root Maven configuration |
| 65 | + |
| 66 | +## Development Workflow |
| 67 | + |
| 68 | +### Making Code Changes |
| 69 | +1. **Always build first** to establish clean baseline: |
| 70 | + ```bash |
| 71 | + mvn clean compile --no-transfer-progress |
| 72 | + ``` |
| 73 | + |
| 74 | +2. **Follow code style** (enforced by checkstyle): |
| 75 | + - Use 2 spaces for indentation (not tabs) |
| 76 | + - Follow Google Java Style Guide |
| 77 | + - Install EditorConfig plugin in your IDE |
| 78 | + |
| 79 | +3. **Validate changes incrementally**: |
| 80 | + ```bash |
| 81 | + # After each change: |
| 82 | + mvn compile --no-transfer-progress |
| 83 | + mvn checkstyle:check --no-transfer-progress |
| 84 | + ``` |
| 85 | + |
| 86 | +### Before Submitting Changes |
| 87 | +**ALWAYS run these validation steps in sequence:** |
| 88 | + |
| 89 | +1. **Code Style Validation**: |
| 90 | + ```bash |
| 91 | + mvn checkstyle:check --no-transfer-progress |
| 92 | + # Must pass - takes ~50 seconds |
| 93 | + ``` |
| 94 | + |
| 95 | +2. **Full Clean Build**: |
| 96 | + ```bash |
| 97 | + mvn clean package -DskipTests=true --no-transfer-progress |
| 98 | + # Must succeed - takes ~2 minutes |
| 99 | + ``` |
| 100 | + |
| 101 | +3. **Documentation**: Update javadoc for public methods and classes |
| 102 | +4. **Contribution Guidelines**: Follow `CONTRIBUTING.md` - PRs must target `develop` branch |
| 103 | + |
| 104 | +## Module Dependencies and Build Order |
| 105 | + |
| 106 | +### Core Module Dependencies (Build Order) |
| 107 | +1. `weixin-graal` (GraalVM support) |
| 108 | +2. `weixin-java-common` (foundation for all other modules) |
| 109 | +3. Core SDK modules (mp, pay, miniapp, cp, open, channel, qidian) |
| 110 | +4. Framework integrations (spring-boot-starters, solon-plugins) |
| 111 | + |
| 112 | +### Key Relationship Patterns |
| 113 | +- All SDK modules depend on `weixin-java-common` |
| 114 | +- Spring Boot starters depend on corresponding SDK modules |
| 115 | +- Solon plugins follow same pattern as Spring Boot starters |
| 116 | +- Each module has both single and multi-account configurations |
| 117 | + |
| 118 | +## Common Tasks and Commands |
| 119 | + |
| 120 | +### Validate Specific Module |
| 121 | +```bash |
| 122 | +# Build single module (replace 'weixin-java-mp' with target module): |
| 123 | +cd weixin-java-mp |
| 124 | +mvn clean compile --no-transfer-progress |
| 125 | +``` |
| 126 | + |
| 127 | +### Check Dependencies |
| 128 | +```bash |
| 129 | +# Analyze dependencies: |
| 130 | +mvn dependency:tree --no-transfer-progress |
| 131 | + |
| 132 | +# Check for dependency updates: |
| 133 | +./others/check-dependency-updates.sh |
| 134 | +``` |
| 135 | + |
| 136 | +### Release and Publishing |
| 137 | +```bash |
| 138 | +# Version check: |
| 139 | +mvn versions:display-property-updates --no-transfer-progress |
| 140 | + |
| 141 | +# Deploy (requires credentials): |
| 142 | +mvn clean deploy -P release --no-transfer-progress |
| 143 | +``` |
| 144 | + |
| 145 | +## Important Files and Locations |
| 146 | + |
| 147 | +### Configuration Files |
| 148 | +- `pom.xml` - Root Maven configuration with dependency management |
| 149 | +- `quality-checks/google_checks.xml` - Checkstyle rules |
| 150 | +- `.editorconfig` - IDE formatting configuration |
| 151 | +- `.github/workflows/maven-publish.yml` - CI/CD pipeline |
| 152 | + |
| 153 | +### Documentation |
| 154 | +- `README.md` - Project overview and usage (Chinese) |
| 155 | +- `CONTRIBUTING.md` - Development contribution guidelines |
| 156 | +- `demo.md` - Links to demo projects and examples |
| 157 | +- Each module has dedicated documentation and examples |
| 158 | + |
| 159 | +### Test Resources |
| 160 | +- `*/src/test/resources/test-config.sample.xml` - Template for test configuration |
| 161 | +- Tests require real WeChat API credentials to run |
| 162 | + |
| 163 | +## SDK Usage Patterns |
| 164 | + |
| 165 | +### Maven Dependency Usage |
| 166 | +```xml |
| 167 | +<dependency> |
| 168 | + <groupId>com.github.binarywang</groupId> |
| 169 | + <artifactId>weixin-java-mp</artifactId> <!-- or other modules --> |
| 170 | + <version>4.7.0</version> |
| 171 | +</dependency> |
| 172 | +``` |
| 173 | + |
| 174 | +### Common Development Areas |
| 175 | +- **API Client Implementation**: Located in `*/service/impl/` directories |
| 176 | +- **Model Classes**: Located in `*/bean/` directories |
| 177 | +- **Configuration**: Located in `*/config/` directories |
| 178 | +- **Utilities**: Located in `*/util/` directories in weixin-java-common |
| 179 | + |
| 180 | +## Troubleshooting |
| 181 | + |
| 182 | +### Build Issues |
| 183 | +- **OutOfMemoryError**: Increase Maven memory: `export MAVEN_OPTS="-Xmx2g"` |
| 184 | +- **Compilation Failures**: Usually dependency issues - run `mvn clean` first |
| 185 | +- **Checkstyle Failures**: Check `.editorconfig` settings in IDE |
| 186 | + |
| 187 | +### Common Gotchas |
| 188 | +- **Tests Always Skip**: This is normal - tests require WeChat API credentials |
| 189 | +- **Multi-Module Changes**: Always build from root, not individual modules |
| 190 | +- **Branch Target**: PRs must target `develop` branch, not `master`/`release` |
| 191 | + |
| 192 | +## Performance Notes |
| 193 | +- **First Build**: Takes 4-5 minutes due to dependency downloads |
| 194 | +- **Incremental Builds**: Much faster (~30-60 seconds) |
| 195 | +- **Checkstyle**: Runs quickly (~50 seconds) and should be run frequently |
| 196 | +- **IDE Performance**: Project uses Lombok - ensure annotation processing is enabled |
| 197 | + |
| 198 | +Remember: This is a SDK library project, not a runnable application. Changes should focus on API functionality, not application behavior. |
0 commit comments