15 July 2014

It is very helpful to be able to set break points in your IDE and attach to a running application to debug what is going on. Java provides this functionality via the JPDA Transport. Additionally, because the Spring Boot Gradle Plugin is built on top of the existing Gradle Application Plugin, it is easy to provide JVM arguments to the Spring Boot application launcher from your Gradle build script:

run {
    jvmArgs = ['-Xdebug', '-Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=y']

When running the Spring Boot application from Gradle, the application will wait on start up until a remote debugger (such as from your IDE) connects to the process on port 4000 via the JPDA Transport protocol:

root@laptop-mbp:~/sample_app$ ./gradlew run
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
Listening for transport dt_socket at address: 4000

Once the debugger is attached, execution will continue on normally, halting only when it comes across any break points set in the debugger.

comments powered by Disqus