Java 如何在 Gradle 中列出测试的类路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26824761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to list classpath for tests in Gradle
提问by zizhuo64062kw
When I try running gradle test
, I get the following output:
当我尝试运行时gradle test
,我得到以下输出:
$ gradle test
:ro:compileJava UP-TO-DATE
:ro:processResources UP-TO-DATE
:ro:classes UP-TO-DATE
:ro:jar
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
ro.idea.ToggleTest > testIsAd FAILED
java.lang.NoClassDefFoundError at ToggleTest.java:13
Caused by: java.lang.ClassNotFoundException at ToggleTest.java:13
ro.idea.ToggleTest > testToggle FAILED
java.lang.NoClassDefFoundError at ToggleTest.java:13
2 tests completed, 2 failed
:test FAILED
So I want to check my classpath to see whether my classpath is wrong or not.
所以我想检查我的类路径以查看我的类路径是否错误。
My question is:How can I list the classpath at test
time with a Gradle task?
我的问题是:如何在test
使用 Gradle 任务时列出类路径?
回答by Peter Niederwieser
You can list test runtime dependencies with:
您可以使用以下命令列出测试运行时依赖项:
gradle dependencies --configuration=testRuntime
Or, if you want to see the actual files:
或者,如果您想查看实际文件:
task printClasspath {
doLast {
configurations.testRuntime.each { println it }
}
}
回答by specialk1st
Also, to list the classpath for the main (non-test) application run use:
此外,要列出主(非测试)应用程序运行的类路径,请使用:
run << {
doLast {
configurations.runtime.each { println it }
}
}
回答by vdshb
Worked for me (Gradle 6.3, Kotlin DSL):
为我工作(Gradle 6.3,Kotlin DSL):
tasks.withType<Test> {
this.classpath.forEach { println(it) }
}