groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gintautas Sulskus <gintautas.suls...@gmail.com>
Subject Groovy config file and the order of property initialisation
Date Tue, 19 Jun 2018 22:02:45 GMT
Hi,

I would like to use the ConfigSlurper to read a groovy config file into a
ConfigObject.
The configuration file contains common and environment-specific properties
as displayed in the example below.

In order to avoid code duplication, I would like to define a common
property 'prop1'. The value of the latter depends on property 'prop2' which
is initialised later depending on the environment setting.

Regardless of the environment set, variable 'prop1' resolves to 'current
env is [:]' which is correct because 'prop2' has not yet been initialised.

Is there a way to defer 'prop1' initialisation until after 'environments'
block? Do I have any other option to solve this?

//groovy config file
prop1 = ‘current env is ’ + prop2   //common value
environments {

test {

prop2 = ‘test’

}

prod {

prop2 = ‘prod’

}

}


Thanks,
Gintas

Mime
View raw message