Thursday, December 4, 2014

Effective Grails plugin development with in-place plugins

Plugins are a great way to modularize your applications and reuse common functionalities. The first time I tried to write a plugin my development process was annoying and time-consuming, because I didn't know about in-place plugins.

My workflow consisted of the following steps, which have to be repeated every time:
  1. change some plugin code
  2. grails package-plugin
  3. grails install-plugin
  4. grails run-app
  5. check plugin changes in main app

So I didn't use plugins for structuring the code for a while, until I found out about in-place plugins, where you can skip a lot of the unnecessary work.

Configure main application for your in-place plugin

You need a plugin under development and a main application where you would like to use it. There you just add the following to your BuildConfig.groovy:
grails-app/conf/BuildConfig.groovy
grails.plugin.location."${pluginName}" = "${pathToYourPlugin}"

Replace the plugin name placeholder with your plugin name and the path to the root directory of your plugin. Check "Specifiying Plugin Locations" in the grails docs Creating and Installing Plugins for further information.

Example for my AdminPanelPlugin used by the AdminTest application:
grails-app/conf/BuildConfig.groovy
grails.plugin.location."AdminPanelPlugin" = "/Users/surelyplus/Documents/workspace/AdminPanelPlugin"

Even IntelliJ has great support for this, so you can see the plugin next to your main app in the Grails View.


Hope this helps you writing more plugins with more fun ( -> like me)!

1 comment:

  1. I would like to help me to know how a plugin structure, i cant use the controller of a plugin in another plugin mi email is pnunez@estudiantes.uci.cu

    ReplyDelete