GSAN GSAN - 3 years ago 109
Groovy Question

How to access to BuildConfig.grooy at runtime in grails 2.3.2

In one of my app service, I need to access to some of the dependencies version I got compile, but I cannot find a way to access to the dependencies at runtime.


BuildConfig.groovy


dependencies {
runtime 'com.oracle:ojdbc14:10.2.0.2.0'
runtime 'com.google.guava:guava:11.0.1'
runtime 'com.thoughtworks.xstream:xstream:1.2.2'
runtime 'org.apache.httpcomponents:httpcore:4.3.1'
}


I need to access any of these dependecies version...
Any ideas?

Answer Source

There is a way to get runtime dependencies, although it will return you all runtime dependencies, including those that were not explicitly defined by you.

BuildSettingsHolder.getSettings().runtimeDependencies.collect { it.name }

This will return you a list of names of all runtime dependencies, e.g.:

enter image description here

You can find dependencies you are interested in and extract their versions from String. I hope it helps you solving your problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download