Reputation: 8414
In my Grails 2.3.5 plugin descriptor file, I'm trying to grab the plugin name or app name, depending on whether its running as a normal Grails app or if the plugin is being run by itself. Its the latter I'm having trouble with.
I've tried the following inside the doWithSpring
closure:
application.metadata.getApplicationName()
application.metadata['app.name']
appName
application.config.appName
this.plugin.name
all of which are either null or an empty Map.
I have a feeling I have to somehow access the current GrailsPlugin
or GrailsPluginUtils
but I haven't made any progress there.
Upvotes: 0
Views: 686
Reputation: 8414
@dmahapatro's answer got me to the desired outcome so I marked his answer as correct.
But the underlying problem I encountered was actually due to a missing attribute in application.properties
- app.name
. So I've extracted the relevant information from the comments and put them in this answer for future reference.
I converted a Grails app to a plugin using the very useful directions from Burt Beckwith on Converting Grails Applications to Plugins and vice versa. In it he suggests:
delete everything from application.properties except the app.grails.version property
This is the reason why my original attempt with application.metadata.getApplicationName()
returned null.
Adding app.name
back into application.properties
, fixed this so that application.metadata.getApplicationName()
gave me the value I needed.
Someone else pointed out this omission in the comments to the blog but Burt has not updated his article or replied to the comment, so I cannot categorically say you should add app.name
to every plugin, only that it worked for me in this instance (YMMV).
Upvotes: 0
Reputation: 50245
You can try using this in plugin descriptor.
import grails.util.Holders
....
def doWithSpring = {
//gives plugin name while using through app
def appName = manager.getGrailsPluginForClassName(this.class.simpleName).name
//gives plugin project name
def name = Holders.config.grails.plugin.myplugin.name
}
Changes in Config.groovy
grails.plugin.myplugin.name=appName
This config entry should not pollute when the plugin is used through the app. You would get an empty map for name
above when plugin is run through the app.
Upvotes: 1