Grails Detect if a Plugin is Installed

…衆ロ難τιáo~ 提交于 2020-01-13 08:49:07

问题


Is there a way in Grails to Detect that a plugin is installed. For example I need to know if the "Acegi" plugin is installed. If it is then I can run different Code. If the plugin is not installed (which is a viable option) then I can run different code.

Thanks in Advance.


回答1:


You can use the plugin manager for this:

import org.codehaus.groovy.grails.plugins.PluginManagerHolder

if (PluginManagerHolder.pluginManager.hasGrailsPlugin('acegi')) {
   ...
}



回答2:


Update for Grails 2.4+

Note that the specific holder classes such as PluginManagerHolder have all been deprecated for several versions of Grails, and removed in Grails 2.4. They have been replaced by a single grails.util.Holders class providing access to all the various application-wide objects through a single access point.

import grails.util.Holders

if (Holders.pluginManager.hasGrailsPlugin('acegi')) {
   ...
}



回答3:


You can use <plugin:isAvailable> and <plugin:isNotAvailable> tags.

Example using OP's acegi plugin:

<plugin:isAvailable name="acegi">
    You have acegi installed!
</plugin:isAvailable>


来源:https://stackoverflow.com/questions/2941216/grails-detect-if-a-plugin-is-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!