I have the following closure:
def deepSave = {
it.attributes.each{it.save(validate: false)}
it.elements.each{deepSave(it)}
it.save(validate: false)
}
I am not sure about the validity of the scenario where you are doing the recursion but when you use closure
for recursion the variable has to be pre-defined before it is tailored so that it can know about itself during recursion. For example:
def deepSave
deepSave = {
it.attributes.each{it.save(validate: false)}
it.elements.each{deepSave(it)}
it.save(validate: false)
}
I could not figure out an exit strategy from the recursion, but I can add some more to it if you can elaborate on the context and add a breaking sample to run.