I did some research on this for a Domain Specific Language I was creating. There are three possibilities:
Create your classes as inheriting a parent groovy class. Put your shared code in the base class.
Use the ScriptBaseClass see http://groovy.codehaus.org/Embedding+Groovy . This is a class upon which all of your scripts will be created.
Use the import static methods capability. Note that you can do this inside the java container (see http://mrhaki.blogspot.com/2011/06/groovy-goodness-add-imports.html ).
All of these work great. My preference is the ScriptBaseClass. This works best if the common code is Groovy (the ScriptBaseClass must be a groovy class. It can not be a java class.)
Of course, with all of these items, you will still need to actually call the common method in your groovy code. For example:
doCommonStuff();
.
. do the rest of it here
.
That's not too awful, I don't think. Certainly about the same as adding some sort of #include pre-processor statement.
And finally, all of this assumes that you have access to the java program which is calling your Groovy code. If that's not the case, you can still use the static imports. It's just one extra line of code.
import static com.mycompany.mycode.doCommonStuff
doCommonStuf()
.
. do the rest of it here
.