Maciej Miklas
Maciej Miklas

Reputation: 3330

Debug gradle internal classes in IntelliJ

I have a custom task, like this one:

task hello { doLast { println 'Hello, World!' } }

Now I can set breakpoint on doLast and IntelliJ will stop there, but I'am unable to debug into gradle core classes, like for example: org.gradle.api.internal.project.DefaultProject#task(...)

Is is possible to attach Gradle sources for debugging Gradle internal classes in IntelliJ?

Upvotes: 3

Views: 665

Answers (1)

62mkv
62mkv

Reputation: 1522

I don't know how to convert comment into answer, but essentially, @m-ricciuti is correct, what has to be done is:

  • add implementation(gradleApi()) (it's in Kotlin DSL) to dependencies
  • specify -all distribution in gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
  • create "Remote JVM Debug" run configuration in IntelliJ (all settings can be left "as is")
  • run gradle with arguments gradlew <task> -Dorg.gradle.debug=true --no-daemon, it will say "Starting daemon" and pause
  • start the created run configuration via Debug button

This way, you can set breakpoints on @TaskAction methods, and a lot more, however, I still was not capable to set a breakpoint in a CloseableHttpClient or an InternalHttpClient classes. Which is essentially what I was most interested in, so if anyone knows more... please chime in!

Upvotes: 4

Related Questions