How to debug Spring Boot from the Gradle command line

In this tutorial, we are going to see how to debug a Spring Boot Application with Gradle using the command line console.

Remember, we learned in a previous post how to run Spring Boot Application. However, it is very common to run Spring Boot in debug mode in our daily development routine.

We can debug Spring Boot from the line command with this command:

Look at this parameter “–debug-jvm”

./gradlew bootRun --debug-jvm

This command will start Spring Boot and wait for us to connect our IDE to the port.

Spring Boot Debug Gradle Console

Now we can your IDE. In this example we use IntelliJ.

For this IDE you have to open menu /run/Edit Configurations

Spring Boot Debug Gradle Console

Now, click on the “plus button” and choose “Remote JVM Debug”

Spring Boot Debug Gradle Console

Change the port number from the same port as the console. Save with the “ok button”.

Give the name you want in order to identify your own debug option.

Spring Boot Debug Gradle Console

Now you can start your application in debug mode.

Spring Boot Debug Gradle Console

Spring Boot Debug Gradle Console

Be careful to start the command first from the console and then from your IDE.

You can perform the same operations mentioned above with the buttons on the toolbar.

Spring Boot Debug Gradle Console

Conclusion:

Here we learned how to start a Spring Boot application in debug mode from the Gradle console and how to start debugging from your IDE by adding a JVM Remote debug.

If you wish to send me any corrections or suggestions, please contact me.
Thanks for your feedback :)

See also