Debugging Gradle build files in Intellij / Android Studio

android, android-studio, gradle, groovy, java

Solution

Original source

1. Create a debugger

- Run -> Edit Configurations

- Add New Configuration

- Add Remote configuration

2. Open debug mode

$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

3. Start debugger

$ ./gradlew someTask -Dorg.gradle.daemon=false #!important, disable daemon mode

4. Attach debugger

- Set breakpoints

- Start debug

5. Disable debug mode

$ unset GRADLE_OPTS

Problem

I am sometimes running into obscure problems with Gradle. Sometimes it helps if i am reading the source files or adding println statements to figure out what i can do and what the state is. But i would really like to just place a breakpoint and list the internal state of variables. is that possible using Android Studio or IntelliJ ? I would also love to ctrl-click to the DSL keywords so i can get some context. Just placing a breakpoint and clicking "debug" from the list of gradle tasks does not work, it just runs the tasks without stopping.

Original source

Related problems