This plugin will mimic the Grails 2 way of handling external configurations defined in grails.config.locations
.
Add dependency to your build.gradle
:
dependencies {
compile 'org.grails.plugins:external-config:1.0.0'
}
To use a snapshot-version
add JFrog OSS Repository to the repositories
:
repositories {
maven { url "https://repo.grails.org/grails/core" }
}
and specify the snapshot version as a dependency:
dependencies {
compile 'org.grails.plugins:external-config:1.0.0-SNAPSHOT'
}
Locate your Grails projects Application.groovy
and implement the trait grails.plugin.externalconfig.ExternalConfig
:
import grails.plugin.externalconfig.ExternalConfig
class Application extends GrailsAutoConfiguration implements ExternalConfig {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
This will add external-config loading to your Grails application.
Then define the property grails.config.locations
. This can be done in either application.yml
like this:
grails:
config:
locations:
- classpath:myconfig.groovy
- classpath:myconfig.yml
- classpath:myconfig.properties
- file:///etc/app/myconfig.groovy
- file:///etc/app/myconfig.yml
- file:///etc/app/myconfig.properties
- ~/.grails/myconfig.groovy
- ~/.grails/myconfig.yml
- ~/.grails/myconfig.properties
or in application.groovy
like this:
grails.config.location = [
"classpath:myconfig.groovy",
"classpath:myconfig.yml",
"classpath:myconfig.properties",
"file:///etc/app/myconfig.groovy",
"file:///etc/app/myconfig.yml",
"file:///etc/app/myconfig.properties",
"~/.grails/myconfig.groovy",
"~/.grails/myconfig.yml",
"~/.grails/myconfig.properties"
]
Notice, that ~/
references the users $HOME
directory.
The plugin will skip configuration files that are not found.
For .groovy
and .yml
files the environments
blocks in the config file are interpreted the same way, as in application.yml
or application.groovy
.