Grails 插件的扩展功能

发布于 2024-10-23 17:52:48 字数 178 浏览 1 评论 0原文

我想知道是否可能,以及是否有通用的方法来扩展 grails 插件的功能。

我最近安装了可评论插件,但需要对其进行一些修改。由于代码不与项目存储在一起(而是存储在用户目录中),因此如果我修改代码,则在更新插件(或安装其他计算机上的项目)后,这些更改都会丢失。

有人有什么想法吗?

谢谢, 尼古拉斯

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) if 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心的憧憬 2024-10-30 17:52:48

如果您想要覆盖某个工件(例如域类),请在您的项目中创建一个同名的工件。插件与应用程序类分开编译,并且首先注册它们的工件,因此如果主应用程序中有工件,它将替换插件的工件。请确保对域类使用相同的包,尽管控制器或服务不需要这样做。

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.

想你只要分分秒秒 2024-10-30 17:52:48

如果您想完全修改插件,您可以尝试更改然后重新编译插件,并将其构建为具有不同名称的zip文件。

然后您可以从源代码安装定制插件。您可以参考此处的问题。

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.

天暗了我发光 2024-10-30 17:52:48

在一个项目中,我们需要一个允许的电子邮件地址列表,允许应用程序在一个环境 (QA) 中向其发送邮件,以便项目中涉及的各个不同各方都可以测试应用程序,而不会有任何邮件发送到的风险我们的客户客户(最终客户)。

更改所有进行邮件发送的代码块的工作量太大,因此我为邮件插件的核心类 (grails.plugin.mail.MailMessageBuilder) 实现了一个自定义扩展程序,该扩展程序从应用程序的配置并覆盖在发送邮件之前解析地址的方法(toDestinationAddresses)。然后,我替换了(插件的)工厂方法,该方法生成 MailMessageBuilders,因此它通过 Grails 引导程序中的 Groovy 元类生成了我的自定义构建器。

这是一个干净、非侵入性的修复,而且效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文