Search code examples
grailsconfigurationconfigbuildconfig

Externalized BuildConfig in Grails


We can load different configuration files for Config.groovy by specifying a class that is a config script. Externalized Configuration:

grails.config.locations = [com.my.app.MyConfig]

Is it possible to do something similar for BuildConfig.groovy?

I want to place CodeNarc configuration in another config file. As it uses Groovy's ConfigSlurper syntax, I try to merge config objects, but not works.

def config = new ConfigSlurper().parse(..)    
this.merge(config)

Any different trick?


Solution

  • You don't need to so that.

    The Codenarc plugin lets you keep your codenarc configuration externally. See here http://grails.org/plugin/codenarc#Configuring The Codenarc Properties

    Included here is an example codenarc setup I have in BuildConfig.groovy

    codenarc.processTestUnit = false
    codenarc.processTestIntegration = false
    codenarc.processViews = true
    codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
    codenarc.ruleSetFiles = [
            "rulesets/basic.xml",
            "rulesets/braces.xml",
            "rulesets/grails.xml",
            "rulesets/groovyism.xml",
    ]
    

    Here we also define an external codenarc.properties file which we use to turn parts of rules from each of the included rulesets on/off. Example of this codenarc.properties file contents is included here:

    # some gsp's MUST have embedded CSS and/or embedded Javascript which requires the use of semicolons.
    UnnecessarySemicolon.doNotApplyToFileNames = *.gsp
    # we're not going to enforce these
    UnnecessaryGString.enabled = false
    UnnecessaryReturnKeyword.enabled = false
    

    So you can steer away from polluting your BuildConfig with un-wanted things as Tomas mentioned.

    Hope this helps.

    Tom