Reputation: 183
If you want to run a Groovy script in Ant, you can either use the script task like this: ..
<script language="groovy">
//foo
</script>
..or the groovy task like that:
<groovy>
//foo
</groovy>
Both ways require the Groovy libraries to be downloaded. I found a promising looking Ant config that does this automatically in this answer: Execute my groovy script with ant or maven
Now for my question:
Which of the two Ant tasks is meant to be used for running Groovy scripts? script
or groovy
?
Also, what is the purpose of the "additional" groovy task, if there's a script task included in Ant that supports groovy?
Also I'd like to quote from a blog post I found here: http://jbetancourt.blogspot.co.at/2012/03/run-groovy-from-ants-script-task.html
Of course, why would you use the 'script' task when the 'groovy' task is available? You wouldn't.
Does anyone agree with the author of this post? If so - could you explain the idea behind it?
Upvotes: 4
Views: 9230
Reputation: 10377
+1 for Josef's statement about the groovy task (btw. his blogs http://josefbetancourt.wordpress.com/ and http://octodecillion.com/ are worth reading)
Using groovy a lot for several purposes, in ant i exclusively use the groovy task because of his slick syntax providing simple access to ant api, consider this example :
<project>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<property name="foo" value="bar"/>
<script language="groovy">
project.setProperty 'foo', 'baz'
echo = project.createTask 'echo'
echo.setMessage 'Howdie :-)'
echo.execute()
</script>
<echo>1. $${foo} => ${foo}</echo>
<groovy>
properties.'foo' = 'baaz'
ant.echo 'Howdie :-)'
</groovy>
<echo>2. $${foo} => ${foo}</echo>
</project>
Which do you prefer ? OK, normally instead of echo. ... you would use print or println,
it's just for demonstrating the access to ant api.
Upvotes: 6