ever been in the position where you just can't figure out what's going on with your gradle build yeah me too it's really frustrating isn't it well fortunately there's a way to figure out exactly what's going on using gradle debug tools so in this video you'll learn three different ways to debug gradle so let's get right into it and the first way i'm going to show you is just using the rde itself and i generally use intellij idea which is a very popular ide for java and gradle development so to illustrate this i've just opened a project here and as soon as i've opened it i've got this big fat error and it says gradle exception unsupported operating system and i can scroll to the code in question and i can see here that here's the gradle exception and say i wanted to delve in and see exactly what's going on with this this code well i could set a breakpoint on the left hand side here by just clicking and then i could open up the gradle panel which is on the right hand side and this has a list of tasks that i can execute and i just need to pick one and right click and then hit the debug button and intellij is going to run that gradle task in debug mode and it's going to attach the editor to that so you can see here actually i've got a breakpoint and the execution of code has stopped on this line and now of course i've got all the support of the debug stuff within the ide such as stepping over lines so i can hit f8 and step over here and seeing variable values and executing any expressions i want to and also browsing the stack here so i've skipped over and i've seen that i'm getting into this particular else block and this might help me to debug what the problem is in this scenario okay so now i've resolved my problem so let's say that now i would like to do some debugging inside one of the plugins that i'm using in this build and we can see up here the list of plugins and let's say that i want to see exactly what's going on inside this com.palantir.docker plugin well what you can do is you can pass a command line argument when you run a build on the command line down here and that will set up a debug session that you can connect to remotely from a different project so just to illustrate this i'm going to run gradle w docker which in this case builds a docker image and on the end of this i need to put in org.gradle.debug equals true and that's a dash d system property so i can hit enter and actually what this is going to do it's going to essentially wait for me to attach a remote debugger to this so you can see right here that it just says starting daemon and it's actually paused so what i'm going to do now is open up this other project which is actually the plugin that i'm using in my project and first up i'm just going to navigate to the code that i want to debug and in this case it is the palantir docker plugin that corresponds to the code that gets executed when i run gradle w docker and let's say i just want to put a breakpoint in here to see what's going on so i'm just going to click on the left hand side here now what i need to do in this project is go into run debug configurations which you get to up here click on add configuration and i need to set up a remote debug configuration so i click the plus icon and go down to remote and i'm just going to call this remote it's going to connect on port 5005 which is the same port that my project is currently listening on and here it says use module class path and i'm just going to select gradle docker.main because i'm debugging the main code there and hit apply and hit okay and now i just hit the debug button and now it says down here connected to the target vm and you can actually see that we've got a break point so if i jump back into the original project you can see that the execution is continuing and now i've stopped execution right here and once again i can just use all the debug tools from the ide to see what's going on inside the code so just to summarize if you pass the dash d org.gradle.debug equals trueflag when you run a gradle task that will suspend execution and wait for a remote debug session and you can open a project and set up a remote debug session and connect into that gradle process and that's useful for doing things like looking into plug-in code and seeing exactly what's going on in a plug-in used by your build now in the third instance here we're inside an actual plug-in project and if you're not on a stage of writing gradle plugins then don't worry and if you are interested i've got a video which is an introduction to gradle plugins but stick along anyway because you might learn something and let's say in this case that i'm in my plug-in project and i'm actually in the process of writing some tests and i've got this test here which is failing for whatever reason and i want to go and debug the code that this test is executing so this is a test that essentially executes a gradle plugin which uses this task class so i would like to put debug point here and i'd like to debug that so you may think that i just need to let's say right click on this test and hit debug well actually that didn't work as expected because it didn't stop at my debug point in fact it's just failed the test again and the reason for this and for anyone that's familiar with writing tests for plugins you might be familiar with the setup of using the gradle runner and the groder runner is a way to create a dynamic temporary gradle build just for your test just for the test duration and in order to debug the execution of the gradle task within that gradle runner we need to add a special parameter here and that is dot with debug and we need to set that to true and now if i run the test in debug mode again lo and behold we've actually stopped execution in the point at which i put the breakpoint and once again we've got all the debug support of the ide including stepping over the code and all that good stuff and just to summarize that again if you are writing a plugin project and you're writing a test that tests that plug-in and that's using the gradle runner then if you want to debug the plug-in code from your test you need to add dot with debug true to the gradle runner builder and then in the actual test itself you'll be able to right click and hit debug and that will stop at whatever break points you've set so i really hope that was helpful and if you've got any of your own tips that you'd like to share please put them down in the comments and likewise if you've got any questions go ahead and ask down there otherwise thanks a lot and i'll see you in the next episode on tom gregory tech