I've managed to enable code reuse by making use of the GroovyShell. The following code:
- Creates a GroovyShell object and sets variables for it to use, notably the context and messageExchange variables.
- Loads and evaluates the script from the files system
def shell = new GroovyShell()
shell.setVariable("context", context)
shell.setVariable("responseFilePath", '${expectedResponseXMLFile}')
shell.setVariable("messageExchange", messageExchange)
shell.evaluate(new File("target/test-classes/shared/soap-assertion.groovy").text)
Using this I can load the same script from the file system in multiple places in my soapUI project. You could in theory have a whole library of scripts that use this technique to hook into soapUI.