Reputation: 18597
I have a Grails plugin that I've written that has its version set using set-version within our continuous integration environment. While building, I'd like to programmatically output the version from within "eventCompileEnd" event hook. So, for my Grails app I can just get the "app.version" metadata but plugin versions are set in the GrailsPlugin.groovy file in the root of the plugin. Is there any way to access that value? Here's the version info I'm referring to:
class MyUtilityGrailsPlugin {
// the plugin version
def version = "4.6.8"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.1 > *"
...etc.
Upvotes: 0
Views: 322
Reputation: 18597
I found that version information can be retrieved from within an event hook for that plugin by doing this:
pluginSettings.getPluginInfo(isPluginProject.getParent()).version;
pluginSettings is a bound variable in the current scope and isPluginProject actually returns a File object that represents the GrailsPlugin.groovy file.
Upvotes: 0
Reputation: 50245
You can use below eventCompileEnd
event in _Events.groovy
of the app to get the name and version of all the plugins used in the app from GantBinding
which is by default available to the post compile event. You can filter your plugin info based on the name
:
//scripts/_Events.groovy
eventCompileEnd = {msg->
msg.supportedPluginInfos.each{println "${it.name} - ${it.version}"}
}
If you want to access the plugin info from any where else (for example: BootStrap) using applicationContext
would be the simplest approach. Something like below would be useful:
//Bootstrap.groovy
def grailsApplication
def init = { servletContext ->
grailsApplication.mainContext.getBean('pluginManager')
.allPlugins.each{plugin->
println "Plugin Info ${plugin.name} - ${plugin.version}"
}
}
In your case, appCtx will not be available in post compile event, so you have to depend on GantBinding
.
Upvotes: 3