禁用 Grails 插件

发布于 2024-07-30 00:56:27 字数 810 浏览 5 评论 0原文

在我的 Grails 应用程序中,我想在运行单元测试时阻止加载 Searchable 插件。 我尝试在 Bootstrap 类中使用以下代码执行此操作

def grailsApplication

def init = {servletContext ->
    def currentEnv = grails.util.Environment.current.name

    if (currentEnv == 'test') {

        def doNothing = {println "Searchable is disabled"}

        // This returns null!
        def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")

        searchablePluginClass.metaClass.doWithDynamicMethods = doNothing 
        searchablePluginClass.metaClass.doWithSpring = doNothing 
        searchablePluginClass.metaClass.doWithApplicationContext = doNothing 
    }
}

但这不起作用,因为 grailsApplication.getClassForName("SearchableGrailsPlugin") 返回 null,大概是因为当此代码时此类不在类路径上运行。 还有其他方法可以禁用此插件吗?

In my Grails app, I want to prevent the Searchable plugin from loading when running my unit tests. I tried doing this using the following code in the Bootstrap class

def grailsApplication

def init = {servletContext ->
    def currentEnv = grails.util.Environment.current.name

    if (currentEnv == 'test') {

        def doNothing = {println "Searchable is disabled"}

        // This returns null!
        def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")

        searchablePluginClass.metaClass.doWithDynamicMethods = doNothing 
        searchablePluginClass.metaClass.doWithSpring = doNothing 
        searchablePluginClass.metaClass.doWithApplicationContext = doNothing 
    }
}

However this doesn't work because grailsApplication.getClassForName("SearchableGrailsPlugin") returns null, presumably because this class isn't on the classpath when this code runs. Is there any other way that I can disable this plugin?

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

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

发布评论

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

评论(3

装迷糊 2024-08-06 00:56:28

我不知道如何禁用该插件,可能有一种方法 本机指南针 XML

使用 grails,您可以通过以下方式使单元测试更容易忍受...
安装这个附加插件:
grails install-searchable-config

这将为您提供一个 grails-app/conf/Searchable.groovy 文件。 您可以编辑
environments.test.searchable 闭包至少禁用bulkIndexOnStartup 和mirrorChanges。

 environments {
 test {
    searchable {
        // disable bulk index on startup
        bulkIndexOnStartup = false
        mirrorChanges = false

        // use faster in-memory index
        compassConnection = "ram://test-index"
    }
}
 }

I am not sure how to disable the plugin, there might be a way with native compass XML

With grails you might be able to make unit testing more bearable with the following...
Install this additional plugin:
grails install-searchable-config

This will give you a grails-app/conf/Searchable.groovy file. You can edit
environments.test.searchable closure to at least disable bulkIndexOnStartup and mirrorChanges.

 environments {
 test {
    searchable {
        // disable bulk index on startup
        bulkIndexOnStartup = false
        mirrorChanges = false

        // use faster in-memory index
        compassConnection = "ram://test-index"
    }
}
 }
骷髅 2024-08-06 00:56:28

要禁用运行测试所使用的测试构建的插件 - 如果您在 BuildConfig.groovy 中包含插件,则可以在其中执行以下操作;

environments {
            development {
                compile ":searchable:0.6.6"
            }
            test {
            }
            production {
                compile ":searchable:0.6.6"
            }
        }
}

这会阻止构建环境在测试时包含该插件,但是,如果您使用此环境构建 UAT 版本,这也会影响测试版本。

To disable a plugin for the test build, which running tests uses - the following is possible in the BuildConfig.groovy if you include your plugin there;

environments {
            development {
                compile ":searchable:0.6.6"
            }
            test {
            }
            production {
                compile ":searchable:0.6.6"
            }
        }
}

This stops the build environment from including the plugin when testing, however, this WILL also effect a test release if you use this environment to build UAT releases.

眼泪淡了忧伤 2024-08-06 00:56:27

我找到了解决方案。 将以下内容添加到 Config.groovy:

environments {
    test {
        plugin {
            excludes = "searchable"
        }
    }
}

I found a solution. Add the following to Config.groovy:

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