I have a script that simply does
// TODO: assign default value if not defined
println optionalParameter
When I invoke it using:
new GroovyShell(new Binding([optionalParameter: 'text'])).evaluate(script)
it works fine. But if I run it without a parameter like below:
new GroovyShell().evaluate(script)
it fails with MissingPropertyException
.
How can I assign default value for optionalParameter
so that I don't get MissingPropertyException
?
Adding this code to script works for me: