You might think debugging a Gradle Spring Boot application in Eclipse couldn't possibly be an issue to work through. Maybe not for most, but I didn't enjoy stepping through Spring Boot apps in the Eclipse IDE without first doing a bit of research.
We'll cover the easy way to configure Debugging, then as a bonus look at how you had to do it not so long ago with Gradle, Environment Variables and Remote Debugging.
As promised, here's the easy way, using Spring Tools Suite and add a Debug Configuration for a Spring Boot App.
Breakpoints, Variables, the whole pizza pie!
We can create Debug Configurations for JUnit testing as well if we want to set breakpoints and debug Test classes. The only “Spring Thing” to remember here is to add the Spring Active Profile setting on the Environment Tab.
Once again, Debugging Goodness, now for @Tests.
Once you have everything in order you can run and debug from the project context menus.
I told you I did some research on this topic and even configured the NixMash Spring Gradle files to support this approach to Eclipse IDE Spring Debugging. It involves three things: 1) Gradle, 2) Environmental Variables, and 3) Eclipse Remote Application Debugging.
We're going to use the Gradle Application Plugin to launch a Java Main Class file, but here's the trick, if a DEBUG Environment Variable is set to “true” we're going to attach a debugger to our Gradle run and test tasks. Here are the tasks.withType() methods added to the project root gradle.build file.
Next we'll launch Gradle from the command line and set the DEBUG variable to “true.”
We're listening…listening…so we can now launch debugging of our Spring Boot app as a Remote Java Application.
Hey, it works just like before, and it's not as ugly as some approaches I've seen out there. It's actually kinda cool.