Debugging - pford68/gradle-examples GitHub Wiki
Contents
Enabling Remote Debugging
Set the org.gradle.debug Gradle property to true.
org.gradle.debug=true
gradle -Dorg.gradle.debug=true build
-
When set to true, Gradle will run the build with remote debugging enabled, listening on port 5005.
-
Note that this is the equivalent of adding the following to the JVM command line:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -
It will suspend the virtual machine until a debugger is attached.
Debugging Tests
To show more information about the failed tests, we can run the tests with the --info flag, but this will also produce a lot of noise. Instead you can we can configure the test task logging by setting the exceptionFormat property to full:
// File: build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:[4,)'
}
test {
testLogging {
exceptionFormat = 'full'
}
}
When we re-run the test task and use the normal logging level, we also get the reason why our test fails, without the extra noise from --info:
$ gradle test
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
com.mrhaki.gradle.SampleTest > sample FAILED
org.junit.ComparisonFailure: expected:<gradle is gr[8]> but was:<gradle is gr[eat]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.mrhaki.gradle.SampleTest.sample(SampleTest.java:8)
1 test completed, 1 failed
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/mrhaki/Projects/mrhaki.com/blog/posts/samples/gradle/testlogging/build/reports/tests/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.906 secs