How to get Grails application name within Config.groovy?

Big Ed picture Big Ed · Mar 21, 2012 · Viewed 8.1k times · Source

I want to include the Grails application name in some of my configuration settings in grails-app/Config.groovy. I've tried many ways without success. For example, if I have the following in my Config.groovy,

edu.appname1 = "${grailsApplication.metadata.'app.name'}"
edu.appname2 = "${application.metadata.'app.name'}"
edu.appname3 = "${metadata.'app.name'}"
edu.appname4 = "${app.name}"

I can run these statements in the Grails console

def edu = grailsApplication.config.edu
println "${'''${grailsApplication.metadata.'app.name'} -> '''}${edu.appname1}"
println "${'''${application.metadata.'app.name'}       -> '''}${edu.appname2}"
println "${'''${metadata.'app.name'}                   -> '''}${edu.appname3}"
println "${'''${app.name}                              -> '''}${edu.appname4}"

with the following results.

${grailsApplication.metadata.'app.name'} -> [:]
${application.metadata.'app.name'}       -> [:]
${metadata.'app.name'}                   -> [:]
${app.name}                              -> [:]

There must be some way to get this information.

Answer

thomj picture thomj · Mar 21, 2012

To get the appName in a config file that you're including with grails.config.locations you can use:

appName = grails.util.Metadata.current.'app.name'