# 构建文件 'build.gradle' 第 12 行，错误：在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象上找不到方法 compile()，参数为 [com.example:lib:1.0]。

- **ID:** `java/gradle-build-script-error`
- **领域:** java
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

'compile' 配置自 Gradle 4.0 起已弃用，并在 Gradle 7.0 中移除；请改用 'implementation'。

## 版本兼容性

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

## 解决方案

1. **Replace compile with implementation** (95% 成功率)
   ```
   dependencies { implementation 'com.example:lib:1.0' }
   ```
2. **Use api if the dependency needs to be exposed transitively** (90% 成功率)
   ```
   dependencies { api 'com.example:lib:1.0' }
   ```

## 无效尝试

- **Reverting to an older Gradle version** — This is a temporary fix and prevents using newer features or plugins. (60% 失败率)
- **Using compileOnly as a direct replacement** — compileOnly does not include the dependency in the runtime classpath, which may cause NoClassDefFoundError. (80% 失败率)
