Grails - How to debug a custom plugin
A few months back when we migrated one of our apps from Grails 1.3.7 to 2.1.1 we lost the ability to dive into the code of our custom plugins while debugging. All we saw was the compiled code, with the ability to attach source but not really knowing where to attach it from because eclipse wouldn't accept the code in the workspace. Since we were strapped for time back then we didn't get a chance to figure out how to debug the code inside the plugins so we made do with lots of debug logging.
Today when I ran into the same issue while working on a new plugin, I didn't have the patience to write all the debug statements. I googled and found nothing! The stackoverflew but nothing came out of it, too. So I went back to the trial and error method and found the solution to that particular pain. Here's a step-by-step guide for anyone who wants to step-in to their custom plugin code:
If you have any reference to the plugin in the main app's BuildConfig, comment it out. (I am talking about any config that looks like grails.plugin.location.myplugin = "../myplugin"
Next, package your plugin.
Install it on your main project the old school way, using the install-plugin command pointing to the zip file created by the package plugin in step 2. You should now have a new entry in your application.properties file.
Run your app and confirm that all's wired up. The debugging still won't work.
Stop the server and uncomment the configuration in BuildConfig or add that config (refer to bullet 1).
And that should do the trick. Did it for me.
When you're done building the plugin you can uninstall the plugin and just leave the config in the BuildConfig file.
If you run into any issues following these steps or know of a better/simpler way to achieve the same, please leave a comment.












