Accessing BuildConfig settings at runtime

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing BuildConfig settings at runtime

Benjamin Wolff
Hi,

I'm looking for a way to access the settings from the BuildConfig.groovy file at runtime.

I know that there is the method GrailsApplication#getConfig(), but after inspecting the flattened output I saw that this config only contains the settings from the Config.groovy. After looking through the code and some web searches I could not find a way to easily access the settings from BuildConfig.groovy.

Could maybe someone hint me to a way of accessing them via dependency injection or the grailsApplication? Since I want to keep it unit testable it I don't want to use static holders.

Thank you!

Cheers,
Ben
Cheers,
Ben
Reply | Threaded
Open this post in threaded view
|

Re: Accessing BuildConfig settings at runtime

sergiomichels
I don't know if grailsApplication holds the BuildConfig information, but your can use ConfigSlurper - http://groovy.codehaus.org/ConfigSlurper - to parse the file.

--
Sérgio Michels


On Wed, Apr 17, 2013 at 11:27 AM, Benjamin Wolff <[hidden email]> wrote:
Hi,

I'm looking for a way to access the settings from the BuildConfig.groovy
file at runtime.

I know that there is the method GrailsApplication#getConfig(), but after
inspecting the flattened output I saw that this config only contains the
settings from the Config.groovy. After looking through the code and some web
searches I could not find a way to easily access the settings from
BuildConfig.groovy.

Could maybe someone hint me to a way of accessing them via dependency
injection or the grailsApplication? Since I want to keep it unit testable it
I don't want to use static holders.

Thank you!

Cheers,
Ben




-----
Cheers,
Ben
--
View this message in context: http://grails.1312388.n4.nabble.com/Accessing-BuildConfig-settings-at-runtime-tp4643718.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Accessing BuildConfig settings at runtime

bksaville
I had the same issue a bit ago, but handled it by storing it in another place such as the grailsApplication.metadata field during build time, which basically relates to application.properties.  You can use the scripts/_Events.groovy file or your own script to do this.  Make sure to persist the metadata afterwards and it will be stored so it can be accessed during runtime.  You'll have to convert for non-string values though.
-Brian


On Wed, Apr 17, 2013 at 12:40 PM, Sergio Michels <[hidden email]> wrote:
I don't know if grailsApplication holds the BuildConfig information, but your can use ConfigSlurper - http://groovy.codehaus.org/ConfigSlurper - to parse the file.

--
Sérgio Michels


On Wed, Apr 17, 2013 at 11:27 AM, Benjamin Wolff <[hidden email]> wrote:
Hi,

I'm looking for a way to access the settings from the BuildConfig.groovy
file at runtime.

I know that there is the method GrailsApplication#getConfig(), but after
inspecting the flattened output I saw that this config only contains the
settings from the Config.groovy. After looking through the code and some web
searches I could not find a way to easily access the settings from
BuildConfig.groovy.

Could maybe someone hint me to a way of accessing them via dependency
injection or the grailsApplication? Since I want to keep it unit testable it
I don't want to use static holders.

Thank you!

Cheers,
Ben




-----
Cheers,
Ben
--
View this message in context: http://grails.1312388.n4.nabble.com/Accessing-BuildConfig-settings-at-runtime-tp4643718.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: Accessing BuildConfig settings at runtime

Jeff Brown-4
In reply to this post by Benjamin Wolff

On Apr 17, 2013, at 9:27 AM, Benjamin Wolff <[hidden email]> wrote:

> Hi,
>
> I'm looking for a way to access the settings from the BuildConfig.groovy
> file at runtime.
>
> I know that there is the method GrailsApplication#getConfig(), but after
> inspecting the flattened output I saw that this config only contains the
> settings from the Config.groovy. After looking through the code and some web
> searches I could not find a way to easily access the settings from
> BuildConfig.groovy.
>
> Could maybe someone hint me to a way of accessing them via dependency
> injection or the grailsApplication? Since I want to keep it unit testable it
> I don't want to use static holders.
>
> Thank you!
>
> Cheers,
> Ben
>



It might depend on what you mean by "runtime".  Do you mean when the build is running, when the application is running, or something else?

If you are talking about when the application is running, can you describe what you are trying to do in the application with values from BuildSettings.groovy?




JSB
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email