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:

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)Code language: JavaScript (javascript)

Software Developer & Technical Lead