Maybe the "if" could forward declare the name(s) like this when not relying on Groovy truth:
if (def x; (x = ...) != null) { } --------- if (def x = ...) { // tests Groovy truth in this form; may be wrapped in parens to check something else about "x" }