How to stop on breakpoint in gradle script using intellij Version: 2016.1.1


(Elad) #1

I have googled and found few old ways to debug gradle script (stopping on breakpoints) from the intellij.

However time has passed and I was wondering if there is an easier way to stop on breakpoints for debugging gradle script in IntelliJ IDEA 2016.1.1?

I also got confused with the different tutorials, and couldn’t find an easy cookbook tutorial on "how to stop on breakpoint in gradle script using intellij"

old tutorials:

post1

post2

post3


(Dimitar Dimitrov) #2

You can put breakpoints in a task or a plugin, but not in your build scripts.

It takes some getting used to, but these days if I need to put a breakpoint in the build script, I take it as a “code smell” that my build is not declarative and I need to extract the imperative logic to a task or a plugin.

The easiest thing is to copy/paste the code in buildSrc and reference it from there. Then you can set your breakpoints, and attach your IDE on port 5005 after running Gradle like this:

gradlew -Porg.gradle.debug=true --no-daemon

(Manoj Shekhawat) #3

Nothing works tried debugging in Eclipse IntelliJ, but no success.

My build.gradle is quite complex. Reading multiple post it looks like we can’t add breakpoints in build.gradle which is fine.

But I have multiple tasks in build.gradle of different types (Test, Exec etc…). Test type tasks invoke TestNG tests calling testing.xml.

I spend last two days trying to bebug my java code using remote, TestNG and simple gradle run configurations. But it never stops at breakpoints. Where I can find some good info.


(Dimitar Dimitrov) #4

@manoj7shekhawat - I am not sure I got it right… Which one of these are you trying to debug?

  • Your build scripts
  • The task and plugins used by your build script
  • Your TestNG tests

Also, where exactly are you putting the breakpoints which are not hit?
A contrived example that we could see would help a lot.


(Elad) #5

i want to debug my build.gradle and my java code when triggred by gradle task.

Java code debugging is the main goal.


(Dimitar Dimitrov) #6

I want to debug my build.gradle and my java code when triggred by gradle task.

Java code debugging is the main goal.

I was going to answer this, but I realized that I already did: How to stop on breakpoint in gradle script using intellij Version: 2016.1.1

To recap, you cannot debug *.gradle scripts; use remote debugging for the plugin code (regardless of the language it is written in).

If it doesn’t work, please detail what are you doing, what are you seeing and what you expected to see.


(Manoj Shekhawat) #7

JavaExec tasks types can be debugged via selecting corresponding tasks in gradle window and running it via Debug mode.