# 在项目 ':app' 中未找到源集 'main'。请确保已应用 java 插件。

- **ID:** `java/gradle-missing-source-set`
- **领域:** java
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

未对项目应用 Java 插件，因此默认源集 'main' 和 'test' 不可用。

## 版本兼容性

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

## 解决方案

1. **Apply the Java plugin to the project** (95% 成功率)
   ```
   plugins { id 'java' }
   ```
2. **Apply the 'java-library' plugin if the project is a library** (95% 成功率)
   ```
   plugins { id 'java-library' }
   ```

## 无效尝试

- **Manually defining the source set without the Java plugin** — The Java plugin provides necessary tasks and configurations; manual definition may lead to missing tasks. (80% 失败率)
- **Using the 'java-library' plugin instead of 'java'** — The 'java-library' plugin extends 'java', so it also works, but the error may persist if not applied. (50% 失败率)
