Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug Java program by executing "gradle run"

Tags:

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?

like image 553
Sky Dog Avatar asked Oct 09 '15 10:10

Sky Dog


People also ask

How do I Debug a Gradle project in Eclipse?

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).

How do I run a Gradle program?

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.

How do I run a Java project in Gradle?

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.


1 Answers

Even though the accepted answer should work, you can achieve it in a much easier way.


  1. 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.

  2. 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).

like image 73
Markus Weninger Avatar answered Oct 26 '22 22:10

Markus Weninger