Plugin Development in Grails


We’ve had a bit of time to jump back into Grails plugin development (or maintenance as it were) and couldn’t be happier to find the recent improvements in Grails 1.1. The biggest improvement (though perhaps not advertised as such) to me, was the inclusion of functionality that allows plugin developers to build test applications against the live, “unpacked” version of the plugin, which is to say, the Grails application that implements the plugin itself.

This may sound esoteric, but to someone doing plugin development in Grails, it’s a life saver, and here’s why.

When building a plugin for Grails, the plugin itself is built as a Grails application. This has many benefits, including in some cases being able to run the plugin and test controllers and domain classes directly in the running plugin. However, most, if not all plugins are intended to plug into another Grails application. Given that, the only real way to test the usability of your plugin API, and whether the plugin works in the context of larger Grails application, is to install the plugin into another Grails application. Here’s an example:

  1. I’m developing Plugins A and B to be installed in a new Grails CMS application I’m building
  2. Plugin A depends on Plugin B to function
  3. Once Plugin B is in good enough shape, I’ll install it into Plugin A using the Grails install-plugin command
  4. Once Plugin A is in good enough shape, I can install it and Plugin B into my Grails CMS application
  5. After testing the CMS for a while, I discover a bug in Plugin B which also requires a small change in Plugin A to accommodate the bug fix (are you still with me?)
  6. I fix the bug in Plugin B and repackage
  7. I remove Plugin B from Plugin A and install the latest version of Plugin B into Plugin A to make the changes required in Plugin A and repackage
  8. In the CMS application, I remove both of the plugins and reinstall both Plugins into the CMS
  9. I become tired of installing and uninstalling plugins and go out for beers

With Grails 1.1, this development cycle is improved drastically. Now, during development you can provide explicit locations for Grails plugin projects, without needing to install the plugin, to develop against that plugin. Here’s an excerpt from the Grails 1.1 release notes:

An application can now load plugins from anywhere on the file system, even if they have not been installed. Simply add the location of the (unpacked) plugin to you BuildConfig.groovy file:

// Useful to test plugins you are developing.
grails.plugin.location.jsecurity = "/home/dilbert/dev/plugins/grails-jsecurity"

// Useful for modular applications where all plugins and
// applications are in the same directory.
grails.plugin.location.'grails-ui' = "../grails-grails-ui"

This is particularly useful in two cases:

  1. You are developing a plugin and want to test it in a real application without packaging and installing it first.
  2. You have split an application into a set of plugins and an application, all in the same “super-project” directory.

Now if you want to test your plugins in the context of a larger application, you can do so without the pain of constant reinstallation.

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!