Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list classpath for tests in Gradle

Tags:

When I try running gradle test, I get the following output:

$ 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?

like image 503
zizhuo64062kw Avatar asked Nov 09 '14 03:11

zizhuo64062kw


People also ask

What is classpath in Gradle?

Annotation Type ClasspathMarks a property as specifying a JVM classpath for a task. This annotation should be attached to the getter method in Java or the property in Groovy. Annotations on setters or just the field in Java are ignored. For jar files, the normalized path is empty.

How does Gradle run tests?

Gradle executes tests in a separate ('forked') JVM, isolated from the main build process. This prevents classpath pollution and excessive memory consumption for the build process. It also allows you to run the tests with different JVM arguments than the build is using.

How do I create a test report in Gradle?

How to generate a Test Report. Gradle generates a Test Report automatically when it runs the entire Test Suite. To do the same, run ./gradlew test (or gradlew. bat test from Windows), or run the test Gradle task from your IDE.


Video Answer


2 Answers

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 }     } } 
like image 140
Peter Niederwieser Avatar answered Sep 24 '22 01:09

Peter Niederwieser


Also, to list the classpath for the main (non-test) application run use:

run << {     doLast {         configurations.runtime.each { println it }     } } 
like image 42
specialk1st Avatar answered Sep 25 '22 01:09

specialk1st