Validate Config Plugin
Dependency:
compile "org.grails.plugins:validate-config:0.4.3"
Summary
Adds methods to ConfigObject for validating expected and required properties.
To use it, specify validate.required and validate.expected in Config.groovy
Installation
grails install-plugin validate-config
Description
Adds methods to Then (usually in To check for required properties callA This way you can validate portions of the config by callingand so on.A
ConfigObject
for validating expected and required properties. This is especially useful when the config has been externalized and you want to ensure values are provided for all the required/expected properties.Validating Expected and Required Properties
Simply add something like this to @[email protected]validate { required = [ "a", "b", "c" ] expected = [ "p":123, "d":"foobar", "q":"/dev/null" ] }
BootStrap.groovy
) to set defaults for missing expected properties callgrailsApplication.config.validateExpectedProperties()
grailsApplication.config.validateRequiredProperties()
ConfigurationException
will be thrown when required properties are missing.The validate.expected
and validate.required
data can be specified at
lower levels too...grails { mongo { validate { required = [ "grails.mongo.host", "grails.mongo.databaseName" ] expected = [ "grails.mongo.port": 27017, "grails.mongo.bucket": "item" ] } } }
grailsApplication.config.grails.mongo.validateExpectedProperties()
Validating Existance of External Files
TheConfigUtils.validateExternalFiles
method will check that a list of
files does exist. Use it like this in Config.groovy
.grails.config.locations << "file:${userHome}/.emacs" grails.config.locations < "file:${userHome}/.grails/${appName}-config.groovy"ConfigUtils.validateExternalFiles(grails.config.locations)
ConfigurationException
will be thrown when any of the files does not exist.