Monday, March 8, 2010

Grails inplace plugin tip - BuildConfig.groovy

Hey... it's late... so lets keep this one short!

(Update: check out this article too! )

I have taken it upon myself to get some re-usable functionality out of our companies grails apps and turn them into plugins.... I thought this was a genius idea but alas I wasn't the person to come up with it... creating grails plugins to modularize your applications is common practice these days.

One headache I came across immediately however was developing an application that depended on a plugin that was also in flux... lets call them MyApp and my-plugin....

I found myself going nuts.... I would come across an error or a shortcoming in my-plugin code while developing MyApp (yes... i am man enough to admit it!!) and had to change the code in my-plugin, do a grails clean.... followed by a grails compile... followed by a grails package-plugin..... ..... FOLLOWED BY ..... a grails install-plugin in MyApp directory... followed by a soul crushing 'y' to confirm installation.... HOLY KEYSTROKES BATMAN!!!!!!!! sorry...

Then I came across a nice solution while pestering Peter Ledbrook on his blog on how to best test plugins....

He pointed me to BuildConfig.groovy in the grails-app/conf folder of MyApp... in there I put the magic words:

grails.plugin.location."my-plugin" = "../my-plugin"

This is basically the path to my-plugin relative to MyApp. I have both in the same workspace directory.

By doing this you only need to package your plugin once to ensure all files are generated.

Now if I find I need to change my-plugin while working in MyApp i simply jump to the source in another IDEA window, make the changes and then restart MyApp.... happy days!!

One word of warning though... I had to remove my-plugin from as from what I could gather... grails didn't know this reference would then relate back to the one BuildConfig.groovy.... this resulted in my-plugin being deleted.... thank the higher beings for version control!!!

Hmmm now I need to figure out how to do a plugin repo for our internal plugins.... another late night maybe....

Hope this helps.... thanks to Peter for his time!