grailsgroovygrails-5

How to Modify Grails 5 Configuration by Adding Groovy Files


I have a large number of Grails 2.5 applications that I want to upgrade to Grails 5, but have been unable to get the configuration to work. In particular, I want my plugin to set up the data source and Spring Security configuration as it did in Grails 2.5.

In my Grails 2.5 applications, I was able to add files to the configuration by adding this code to the top of Config.groovy.

if (!grails.config.location || !(grails.config.location instanceof List)) {
    grails.config.location = []
}
    
grails.config.location << ["classpath:jcc-server-config.properties"]
grails.config.location << ["classpath:SecurityConfig.groovy"]

But this doesn't work in Grails 5. I've tried adding an application.groovy file, but everything defined in the application.yml seems to be set in stone. Has anybody found a way to add a Groovy file to the Grails configuration that will override or add to the settings in application.yml? YAML will not do because I have logic embedded in the configuration to make it work correctly in different environments.

Thanks.


Solution

  • Did you remember to include the external-config dependency? i.e.

    implementation 'dk.glasius:external-config:3.0.0'
    

    Re' your question on accessing config values this way, there should be no difference, in my apps I get to the config either via grailsApplication.config, or if grailsApplication isn't immediately available(e.g. classes under src), then with Holders, i.e. Holders.grailsApplication.config.