I'd need to define and read by ConfigSlurper several properties from a Groovy configuration file which will share some common fields and add just one specific field. Something like this:
config {
// this is something like abstract property
common {
field1 = 'value1'
field2 = 'value2'
}
property1 {
// include fields from common here
customField = 'prop1value'
}
property2 {
// include fields from common here
customField = 'prop2value'
}
}
I'm curios whether it is possible to achieve this somehow in a nice way. As I'm not very familiar with Groovy so my current solution is not ideal I'd say:
config {
common {
field1 = 'value1'
field2 = 'value2'
}
property1 = common.clone()
property1 {
customField = 'value'
}
property2 = common.clone()
property2 {
customField = 'value'
}
}
config.remove('common')
Thanks for any advice
You can do:
config {
// A common map of values
def common = [
field1: 'value1',
field2: 'value2'
] as ConfigObject
property1 {
customField = 'value'
}
property2 {
customField = 'value'
}
property1.merge(common)
property2.merge(common)
}
Is that the sort of thing you mean?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With