Grails Goodness: Change Base Name For External Configuration Files
With Grails 3 we get the Spring Boot mechanism for loading external configuration files. The default base name for configuration files is application
. Grails creates for example the file grails-app/conf/application.yml
to store configuration values if we use the create-app
command. To change the base name from application
to something else we must specify a value for the Java system property spring.config.name
.
In the following example we start Grails with the value config
for the Java system property spring.config.name
. So now Grails looks for file names like config.yml
, config.properties
, config-{env}.properties
and config-{env}.yml
in the default locations config
directory, root directory on the filesystem and in the class path.
$ grails -Dspring.config.name=config run-app
...
To pass the system properties when we use Grails commands we must change our build.gradle
and reconfigure the run tasks so any Java system property from the command line are passed on to Grails:
...
tasks.findAll { task ->
task.name in \['run', 'bootRun'\]
}.each { task ->
task.systemProperties System.properties
}
Remember that if we use this system property the default grails-app/conf/application.yml
is no longer used.
Written with Grails 3.0.8.