11

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.

Big Ed
  • 1,056
  • 9
  • 20

2 Answers2

25

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'
thomj
  • 383
  • 1
  • 3
  • 14
  • I am googling this statement. It works for me on grails 2.3.11. Thanks! – Tung Mar 21 '16 at 13:49
  • 1
    Perfect it is just what I need. You can also use grails.util.Metadata.current.getApplicationName() as an equivalent – Nico Sep 21 '16 at 13:03
2

try this:

edu.appname1 = appName

or if you want to use as part of a longer configuration parameter

edu.appname1 = "something.$appName.else"
Dónal
  • 185,044
  • 174
  • 569
  • 824
  • My problem was that it wasn't available in a file I included via `grails.config.locations`. I'll just save it to a new property in `Config.groovy` and use that. – Big Ed Mar 21 '12 at 17:39