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

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

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

在跑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.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5683421.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存