ConfigSlurper
ConfigSlurper is a utility class within Groovy for writing properties file like scripts for performing configuration. Unlike regular Java properties files ConfigSlurper scripts support native Java types and are structured like a tree.
Below is an example of how you could configure Log4j with a ConfigSlurper script:
To load this into a readable config you can do:
As you can see from the example above you can navigate the config using dot notation and the return values are Java types like strings and booleans.
You can also use scoping in config scripts to avoid repeating yourself. So the above config could also be written as:
Converting to and from Java properties files
You can convert ConfigSlurper configs to and from Java properties files. For example:
Merging configurations
You can merge config objects so if you have multiple config files and want to create one central config object you can do:
Serializing a configuration to disk
You can serialize a config object to disk. Each config object implements the groovy.lang.Writable interface that allows you to write out the config to any java.io.Writer: