Exclude plugin for specific environment

断了今生、忘了曾经 提交于 2019-12-22 05:33:07

问题


I'm using grails 2.1.

I need to exclude a plugin when building for production.

This post mentions adding scopes to the plugins. I believe this requires editing indivudual plugin descriptors?

I would like to define plugins to exclude in one location.

I have tried adding the following to config.groovy:

environments {
    production {
    plugin.excludes='grails-melody'
    }
}

When I check the war it still contains the melody folder under WEB-INF/plugins.

I should add that most of the application plugins are specified in application.properties as follows:

plugins.build-test-data=2.0.3
plugins.fixtures=1.1
plugins.geoip=0.2
plugins.grails-melody=1.12
etc...

How can I exclude specific plugins for production builds?

Thanks


回答1:


In your buildConfig.groovy you can define a plugin to not export:

plugins {
  compile(':theplugin:theversion') {
    export = false
  }
}



回答2:


let me throw an answer in the ring. Similar to what @hitty5 is proposing, but with some changes (and a bug fix).

For us, it is important to exclude some page speed plugins, when working on the DEVELOPMENT environment, as we want to see the resources in full. On the other hand we don't want to copy the plugins that should be on every machine between blocks (like you would have to in @hitty5 's solution).

plugins {
    runtime ":hibernate:$grailsVersion"
    // ... some more plugins that I want in every environment

    if (Environment.getCurrent() in [Environment.PRODUCTION, Environment.TEST]) {
        // plugins, that I only want on the test and production servers
        println("BuildConfig: including page speed optimization plugins.")
        runtime ":zipped-resources:1.0"
        compile ":cache-headers:1.1.5"
        runtime ":cached-resources:1.0"
        runtime ":yui-minify-resources:0.1.5"
    }

    // ... and more plugins, if you like
    build ":tomcat:$grailsVersion"

}

Hope this helps.

All the best, fluxon




回答3:


first i recommend to use the build config file (BuildConfig.groovy) to resolve your plugin dependencies. inside this file you can define env specific blocks like:

if (environment == Environment.PRODUCTION){
    plugins {            
            compile ":<plugin>:<version>"
        }
    }
else {
        plugins {            
            compile ":<plugin>:<version>"
        }
}



回答4:


In your BuildConfig.groovy you can define a plugin to not export in a specific environment:

    plugins {
      compile(':theplugin:theversion') {
         if (Environment.getCurrent() == Environment.PRODUCTION) {
            export = false
         }
      }
    }

Remember to add

import grails.util.Environment

at the beginning of BuildConfig.groovy



来源:https://stackoverflow.com/questions/14501444/exclude-plugin-for-specific-environment

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