java build_error ai_generated true

在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象上找不到方法 testImplementation(),参数为 [junit:junit:4.13.2]。

Could not find method testImplementation() for arguments [junit:junit:4.13.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

ID: java/gradle-missing-test-framework

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-12-20首次发现

版本兼容性

版本状态引入弃用备注
7+ active

根因分析

在未应用 Java 插件的项目中使用了 'testImplementation' 配置,该插件提供测试配置。

English

The 'testImplementation' configuration is used in a project that does not apply the Java plugin, which provides the test configurations.

generic

解决方案

  1. 95% 成功率 Apply the Java plugin to the project
    plugins { id 'java' }
  2. 70% 成功率 Use the 'test' configuration if the Java plugin is not desired (deprecated)
    testCompile 'junit:junit:4.13.2' (though deprecated, works in older Gradle)

无效尝试

常见但无效的做法:

  1. Adding testImplementation to the root project without applying the Java plugin 90% 失败

    The test configuration is only available after applying the Java plugin.

  2. Using compileOnly instead of testImplementation 85% 失败

    compileOnly does not include the dependency in the test classpath.