2

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.

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
Big Ed
  • 1,056
  • 9
  • 20
  • Did you remember to include the external-config dependency? i.e. implementation 'dk.glasius:external-config:3.0.0' – David Brown Nov 20 '22 at 22:10
  • Thanks. That gets me a long way toward my goal. Do you know how to access the existing configuration values from within the Groovy files that I include this way? – Big Ed Nov 22 '22 at 13:49
  • I found that you use grails.util.Metadata.current.getApplicationName() to get the application name, and the other properties will fill in as before. @DavidBrown - Would you please add your comment as an answer so I can accept it? – Big Ed Nov 22 '22 at 20:00

1 Answers1

1

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.

David Brown
  • 3,021
  • 3
  • 26
  • 46