Monday, 23 January 2012

Grails plugin: use the "loadAfter" property

I recently wrote a plugin that will extend the class of one of Grails' beans, and replaces Grails' bean with itself. However, I ran into a funky error where sometimes my bean had replaced Grails', and at other times the Grails default bean was in the context.

Turns out that we can use the "loadAfter" property in the PluginNameGrailsPlugin.groovy class.

By specifying a list of plugin names here, we can control the order that grails will load your applications. In my instance, my plugin was sometimes being loaded before the controllers and groovy pages plugins. I managed to consistently get my plugin to load after these two using the following:


def loadAfter = ['controllers', 'groovyPages']


See the official documentation for more information.

No comments: