I have a Gradle project in Eclipse IDE and I usually use the option gradle run
to run my Java application.
I have an error in my Java code and I want to debug it, but when I execute gradle run
, the debugger doesn't stop in the breakpoints. In the "Debug as" menu, I don't have anything like gradle debug
.
How can I debug my application?
Open Eclipse and go to Run -> Debug Configurations.... Select the Remote Java Application in the list of configuration types on the left. Click the New toolbar button. In the Project field of the Connect tab, type or browse to select the project to use as a reference for the launch (for source lookup).
You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class.
This chapter explains how to build a java project using Gradle build file. First of all, we have to add java plugin to the build script, because, it provides the tasks to compile Java source code, to run the unit tests, to create a Javadoc and to create a JAR file. Use the following line in build. gradle file.
Even though the accepted answer should work, you can achieve it in a much easier way.
Just run gradle run --debug-jvm
. This starts the application in remote debug mode, and you can attach with any remote debugger, e.g., Eclipse, on port 5005
.
Assuming you use Eclipse as IDE: In Eclipse, go on your Project -> Debug as... -> Debug Configuration -> Remote Java Application. As host set localhost
, as port 5005
, and you are free to go.
For more information see the official Gradle Java plugin doc regarding testing.
[...] can also be enabled at invocation time via the --debug-jvm task option (since Gradle 1.12).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With