1

I'm able to get values from the application's application.properties using grailsApplication.metadata[key], but I'm having a hard time getting the same for a loaded Grails plugin.

I've tried grailsApplication.mainContext.getBean('pluginManager').allPlugins but the instances in that list don't contain the values from the plugins' applications.properties files.

I've also tried GrailsPluginUtils.getMetadataForPlugin(pluginName), but that doesn't return the values from applications.properties either. (In fact, I usually get null.)

Is there a way to get to these values at runtime?

Michael Hellein
  • 4,378
  • 1
  • 25
  • 21

2 Answers2

2

@Michael answer can be made nicer indeed. Add a def grailsApplication where needed, then access your property app.myprp using something like ${grailsApplication.metadata.'app.myprp'}.

mohsenmadi
  • 2,277
  • 1
  • 23
  • 34
-1

I don't like this as an answer, so I'm hoping that someone will still point me in the right direction.

Because I can't find a way to get to the plugin metadata, I'm reading the plugin application.properties files manually (following https://stackoverflow.com/a/20872275/489597):

import org.codehaus.groovy.grails.plugins.GrailsPluginUtils

GrailsPluginUtils.getPluginDirectories().collect {
    Properties properties = new Properties()
    File propertiesFile = new File("${it.getPath()}/application.properties")
    propertiesFile.withInputStream {
        properties.load(it)
    }
    properties
}

It's been pointed out to me that this won't work in a packaged WAR, because the application.properties files won't be present unless perhaps they're copied into WEB-INF.

Community
  • 1
  • 1
Michael Hellein
  • 4,378
  • 1
  • 25
  • 21