开发者

Extending functionality of Grails Plugin

I would like to know, if it is possible and if there is a generic way to extend the functionality of a grails plugin.

I recently installed the commentable plugin, but need to do some modifications to it. Since the code is not stored together with the project (but in the user directory) i开发者_Python百科f I modify it, after the plugin is updated (or the project at some other machine installed) these changes are lost.

Does someone have any idea?

Thanks, Nicolas


If you want to override an artifact (e.g. a domain class) create one with the same name in your project. Plugins are compiled separately from the application classes and their artifacts are registered first, so if there's an artifact in the main app it will replace the plugin's. Just be sure to use the same package for domain classes, although this isn't required for controllers or services.


If you want to modify the plugin completely, you may try to change and then recompile the plugin, and build it into a zip-file with different name.

Then you can install the customized-plugin from source code. You may refer to the question here.


In one project we needed a list of allowed email addresses, that the app was allowed to send mail to, for one environment (QA) so various different parties involved in the project could go testing the app without the risk of any mail be sent to our customers customers (end customers).

It was too big a job to change all code-blocks that did the mailing so I implemented a custom extender for a core class of the mail-plugin (grails.plugin.mail.MailMessageBuilder) that took a list of allowed email addresses from the app's config and overrode a method that resolved the addresses before sending the mail (toDestinationAddresses). I then replaced a factory method (of the plugin), that produces MailMessageBuilders so it produced my custom builders, via Groovy metaClass in Grails bootstrap.

This was a clean, non-intrusive fix and it worked nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜