How to debug Gradle Plugins with IntelliJ

How to debug Gradle Plugins with IntelliJ #

Intellj’s Remote Java Debugging will allow you to debug a Java program or application that is running on another machine or a server environment. We can use this feature to debug a custom gradle plugin that develops locally.

Steps #

  1. Create a new “Remote JVM Debug” in the plugin project that is going to debug.
  • Go to Run then Edit Configurations
  • Click Add New Configuration and select Remote JVM Debug
  • Configure the following properties: (For debugging locally, can just use the default values, e.g. localhost:5005)
    • Name: Give the configuration a name. (default: Unnamed)
    • Host: Enter the address of the machine where the host and port app will run. (default: localhost:5005)
    • Command line arguments for remote JVM:
      • Select JVM arguments format - this should match your JDK version
      • The VM options that the host application needs to be started with by default:
        -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
        
  1. Run Gradle task (from the project that uses the plugin) with some additional parameters:
./gradlew tasks -Dorg.gradle.debug=true --no-daemon

It will be waiting for the debugger to be attached when the command starts running.

  1. Set breakpoints in Gradle plugin source code where you want to debug.

  2. Attach the debugger by click Debug button or shift+F9 in the Gradle plugin project.

References #