Reputation: 11397
When I deal with a new java source that is new to me, I usually debug and follow its behavior at runtime, see the states of objects, sometimes execute expressions on the go and observe how system works. That helps to learn the new source code very fast, even start solving problems without knowing it all.
Now with gradle which uses groovy (thus we lack compile time safety and proper autocompletion) I want to use same approach as gradle build is a magic to me yet. I want to set a breakpoint just like in regular java code, stop there, see what's available what objects have what states etc. Just looking around.
How do we do this with gradle?
Currently I'm doing something like this to have some idea whats some objects are consisted of etc., but that's clearly not enough.
import groovy.json.*
defaultTasks 'main'
apply plugin: 'java'
task main << {
println new JsonBuilder( convention ).toPrettyString()
}
Upvotes: 3
Views: 3215
Reputation: 28136
If you want to debug gradle script, then this short tutorial could be usefull to you.
The main thing is, that Idea starts a deamon to execute a gradle tasks and you have to attach the debugger to the remote process. To do it, you need to modify GRADLE_OPTS environment variable to enable remote debugging, by adding to it:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
Then you need just to configure a remote debugging in Idea, start your script via command line and then attach the debugger to it.
Upvotes: 1