# 项目 com.example:my-app:1.0.0 在依赖图中存在循环。循环：my-app -> module-a -> module-b -> my-app

- **ID:** `java/maven-cyclic-dependency`
- **领域:** java
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

两个或多个模块直接或间接相互依赖，导致循环依赖。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 8+ | active | — | — |

## 解决方案

1. **Refactor the project to remove the circular dependency by extracting shared classes into a new module** (90% 成功率)
   ```
   Create a new module 'shared' and move common code there, then have both modules depend on 'shared'.
   ```
2. **Use dependency exclusions to break the cycle** (70% 成功率)
   ```
   <dependency><groupId>com.example</groupId><artifactId>module-a</artifactId><exclusions><exclusion><groupId>com.example</groupId><artifactId>my-app</artifactId></exclusion></exclusions></dependency>
   ```

## 无效尝试

- **Removing one dependency entirely without refactoring code** — The code may rely on classes from that dependency, causing compilation errors. (80% 失败率)
- **Using optional dependencies to break the cycle** — Optional dependencies are still resolved during compilation, so the cycle persists. (90% 失败率)
