I found a solution on the web. Just add this line into the start of the code:
this.getClass().classLoader.rootLoader.addURL(new File("file.jar").toURL())
Better still, use a list:
[ "file1.jar", "file2.jar" ].each {
this.getClass().classLoader.rootLoader.addURL(new File(it).toURL())
}