Debug Gradle plugins with IntelliJ

后端 未结 3 577
南方客
南方客 2020-12-12 15:32

Problem

I want to use the interactive debugger with IntelliJ. Unfortunately, I can\'t convince IntelliJ to load and compile the plugin. Ho

相关标签:
3条回答
  • 2020-12-12 15:37

    First, it sounds like there is a problem with your IDEA Gradle project. If you run gradlew cleanIdea idea and then open the generated project from IDEA (rather than using the JetGradle plugin), all should be fine.

    Second, if you still can't get the GradleMain/GradleLauncher (the former class does exist) approach to work, another approach is to debug the Gradle build as an external application. For that you need to add -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the GRADLE_OPTS environment variable, run the build from the command line, wait until it suspends, and then start a "Remote" run configuration (with corresponding settings) from IDEA. At that point the debugger should connect to the Gradle process and you should be up and running.

    0 讨论(0)
  • 2020-12-12 15:44

    IntelliJ IDEA 12.1 provides ability to debug gradle tasks out of the box - right-click target task at the JetGradle tool window tasks list and choose 'debug'

    0 讨论(0)
  • 2020-12-12 15:52

    I was able to debug gradle sources (including plugins) using -Dorg.gradle.debug=true (found on gradle forum):

    1. Stop daemons if any:

      ./gradlew --stop

    2. Run

      ./gradlew <task> --no-daemon -Dorg.gradle.debug=true

    3. Connect remotely to gradle process (port 5005) - if using IntelliJ IDEA, see OP's image above

    It should stop on breakpoints now.


    BTW, I have created a separate IntelliJ IDEA project for gradle sources. Since I use gradle wrapper, I have grabbed the sources from

    ~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src

    In IDEA I did File->Import Project, then selected the above path, then - "Create project from existing sources". Hit Next couple of times (made sure I didn't include any jars from lib/plugins directory, since IDEA would complain that most project files already exist).

    I then created a remote debug configuration in that IDEA project and used it for debugging gradle.

    0 讨论(0)
提交回复
热议问题