Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Changing the Grails project configuration from within a plugin

This code snippet shows how to update project Configuration settings from a Grails Plugin executable script. The script changes the configuration by copying the settings from a default config file, placed in the plugin's folder, to the Config.groovy. This is usually very useful during a plugin installation when you need to provide some default configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
includeTargets  grailsScript("_GrailsInit")

target(quickstart: 'Configures project to use [your plugin name] Plugin') {
    def configFile = new File("${basedir}/grails-app/conf/", 'Config.groovy')
    def defaultConfigFile = new File("${[your plugin name]PluginDir}/src/samples/",
        'conf/DefaultConfig.groovy')
    if (configFile.exists() && defaultConfigFile.exists()) {
       defaultConfigFile.eachLine { line ->
           configFile.append("\n${line}")
       }
       println '* Your grails-app/conf/Config.groovy has been updated.'
    } else {
       println '* Cannot update grails-app/conf/Config.groovy.'
    }
}

setDefaultTarget(quickstart)


This post first appeared on Programming | SysGears - Custom Software, please read the originial post: here

Share the post

Changing the Grails project configuration from within a plugin

×

Subscribe to Programming | Sysgears - Custom Software

Get updates delivered right to your inbox!

Thank you for your subscription

×