3

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?

Maciej Miklas
  • 3,305
  • 4
  • 27
  • 52
  • maybe this helps : https://stackoverflow.com/a/51884925/6899896 ? also, you should configure the gradle wrapper to use a '*-all' distribution (e.g. `distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip` ) – M.Ricciuti Nov 21 '18 at 09:35
  • 2
    You migth also have to add dependency "gradleApi() ( `dependencies { compileOnly gradleApi() }` ) to make Gradle source code available for debug – M.Ricciuti Nov 21 '18 at 09:51

1 Answers1

3

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!

62mkv
  • 1,444
  • 1
  • 16
  • 28