6

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

Community
  • 1
  • 1
Thomas Buckley
  • 5,836
  • 19
  • 62
  • 110
  • FYI: I upvoted this because I think that shows research effort :) –  Jan 24 '13 at 12:49
  • Sérgio, you're a comedian as well as developer! ;) Thanks :) – Thomas Buckley Jan 24 '13 at 15:40
  • @ThomasBuckley Solution is not working for me in grails 2.4.3 version,I want to exclude a plugin in development mode.Can you give any idea? – Ankit Gupta Dec 23 '14 at 07:09
  • @AnkitGupta I havent worked on Grails in over 18 months, it's a distant memory for me! I'd suggest posting a new question with your code, environment setup and the issue. Maybe link back to this to show you done some searching ;) – Thomas Buckley Dec 30 '14 at 14:27

4 Answers4

8

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

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

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

fluxon
  • 538
  • 7
  • 19
  • Is it working if use it in a plugin dependencies list. For example I have plug in A that use plugin B for development mode. If an application that depends to my plugin A, can have plugin B only in development mode that I specified with your condition in plugin A BuildConfig ? – Omid Apr 07 '15 at 09:54
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>"
        }
}
hitty5
  • 1,653
  • 12
  • 25
  • Hey there, thanks for adding your solution. Like that, it doesn't work for me as `environment` is not defined. However, if I replace it with `Environment.getCurrent()` it works fine. – fluxon May 31 '13 at 11:20
  • I checked the WAR file and the Java Melody plugin gets bundled as I want. However in the production WAR(without jmelody) file I still see a class named: grails.plugin.melody.GrailsMelodyUtil (and nothing else related to jmelody) – Suraj Mar 15 '14 at 12:59
3

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

  • Solution is not working for me in grails 2.4.3 version,I want to exclude a plugin in development mode.Can you give any idea? – Ankit Gupta Dec 23 '14 at 07:10
  • There needs to be more emphasis on `import grails.util.Environment`. That little bugger is too easy to miss. – burns Feb 22 '19 at 19:28