I had the same kind of issue in the past, using Groovy 1.8.1. I couldn't find in the documentation how to use several script files within the same <groovy>
task (see also the ant <script>
task's doc). Using several tasks didn't work either for me, because the context was reset between them.
I haven't upgraded to Groovy 2.x.y as I don't use it that much. Below I illustrate a possible workaround with 1.8.1; perhaps it's still valid.
<property name="home" location="/Users/coyote/mytest/ant/src"/>
<property name="gscript1" location="${home}/my/own/pack/foo.groovy"/>
<property name="gscript2" location="${home}/my/own/pack/bar.groovy"/>
<groovy>
evaluate( new File(properties.'gscript1') );
evaluate( new File(properties.'gscript2') );
</groovy>
evaluate()
takes either a String or a Script file, on which it performs a dynamic evaluation -according to the API doc- using the current bindings. Those are the bindings of the <groovy>
task, I presume.
I'm not sure I understand your use case, but with this model you can of course define constants first; hardcoded, as properties + code, or in a groovy-script-file + evaluate.