There are two very simple solutions to this: a) the typical "scripting" approach b) the more groovy-ish approach
a) is simply prepending your script-String with a String that defines your methods. b) is putting a reference into the binding, e.g. under the name "test". The value of that reference is a Closure object or any other object that has a "call(args)" method. When while executing the Script, Groovy sees "test()", it will first try to find such a method and if no such method is there it tries to resolve "test" as a property and will find it in the binding. Then it will call the so resolved reference (closure) with the provided arguments (if any).
There are even more advanced options like providing a CompilerConfiguration, which are all listed in the DSL chapter of "Groovy in Action, 2nd edition" (shameless plug).