Disable Grails plugin

无人久伴 提交于 2019-12-12 10:39:28

问题


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?


回答1:


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

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



回答2:


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"
    }
}
 }



回答3:


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.



来源:https://stackoverflow.com/questions/1179895/disable-grails-plugin

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