In this 2016 thread, debugging Gradle tasks from Buildship was on the roadmap; the workaround is still --debug-jvm plus a Remote Java Application in Eclipse. I wrote an open-source plugin that does it in one click, and I would like feedback from Buildship users and maintainers.
What it does. It adds Debug Gradle Tasks to the context menu of the Gradle Tasks view and a debug mode to Gradle Task run configurations. Every JVM the build forks (JavaExec, Test, bootRun, …) is attached to the Eclipse debugger.
How it works.
- Eclipse listens with JDT’s Socket Listen connector on a free port.
- An init script, added through Buildship’s
invocationcustomizersextension point, setsdebugOptionson everyJavaForkOptionstask:server=false,suspend=true, the port read lazily from a system property, so the configuration cache is reused across debug sessions. - During the session, a saved Java file is compiled by Gradle (
classes) and the class files it rewrote go to JDT’s hot code replace. Classes compiled by ECJ cannot replace classes compiled by javac: their lambda methods have different names.
Two questions for the Buildship team.
- Reading the selection of the Gradle Tasks view needs Buildship’s internal node classes, which
org.eclipse.buildship.uidoes not export. Would a small public API for the selected tasks be welcome? - Buildship runs builds inside
IWorkspace.run, which holds back Eclipse’s auto-build until a long-running task such asbootRunends. Is that intended for run configurations?
GitHub: GitHub - legrottagliegionata/eclipse-gradle-debug: Debug any Gradle task from Eclipse's Gradle Tasks view, as in IntelliJ IDEA · GitHub (EPL 2.0, Eclipse 2024-06 or later, also on the Eclipse Marketplace). Write-up with the details: Debugging Gradle tasks in Eclipse, the way IntelliJ does it - DEV Community
Disclosure: I am the author of the plugin.