Could not find method testCompile() for arguments [{group=junit, name=junit, version=4.11}]问题的解决

本文档指导你在Outtertune项目中遇到的testCompile配置变更问题,介绍了如何将testCompile更改为testImplementation以解决编译错误,并概述了Gradle API调整背后的原因和步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在跑outtertune的项目,遇见了一个错误。 

 错误代码:


dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    runtime fileTree(dir: 'libs', include: '*.jar')
    compile group: 'net.sourceforge.collections', name: 'collections-generic', version: '4.01'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'

新版本中,testCompile改为了testImplementation,所以报错,找不到testCompile()方法,把testCompile改为testImplementation即可

老版本的gradle已经对一些配置名字进行了修改

使用implementation、api, 代替compile ,

testImplementation 代替testCompile

androidTestImplementation 代替 androidTestCompile

正确方式:


    testImplementation group: 'junit', name: 'junit', version: '4.11'

拓展知识:build.gradle的步骤以及原因:

1、将java库插件应用于API和实现分离。

2、使用Maven Central解析依赖项。

3、使用JUnitJupiter进行测试。

4、这个依赖项被导出到使用者,也就是说在他们的编译类路径上找到。

5、此依赖关系在内部使用,不会在使用者自己的编译类路径上公开给使用者。


//https://docs.gradle.org/current/samples/sample_building_java_libraries.html


Apply the java-library plugin for API and implementation separation.
Use Maven Central for resolving dependencies.
Use JUnit Jupiter for testing.
This dependency is exported to consumers, that is to say found on their compile classpath.
This dependency is used internally, and not exposed to consumers on their own compile classpath.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七咔七咔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值