Ant中的Groovy脚本:使用脚本任务还是groovy任务? [英] Groovy scripts in Ant: Use script task or groovy task?

查看:208
本文介绍了Ant中的Groovy脚本:使用脚本任务还是groovy任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要在Ant中运行Groovy脚本,则可以使用脚本任务是这样的:..

If you want to run a Groovy script in Ant, you can either use the script task like this: ..

<script language="groovy">
//foo
</script>

..或常规任务:

<groovy>
//foo
</groovy>

两种方法都需要下载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

现在是我的问题:

这两个Ant任务中的哪个将用于运行Groovy脚本? scriptgroovy?

Which of the two Ant tasks is meant to be used for running Groovy scripts? script or groovy?

此外,如果Ant中包含一个支持groovy的脚本任务,那么额外的" 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

当然,当"groovy"任务可用时,为什么还要使用"script"任务?你不会的.

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?

推荐答案

+1,以获取约瑟夫(Josef)关于常规任务的声明(顺便说一下,他的博客 http://octodecillion.com/值得阅读)
出于多种目的而大量使用groovy,在ant中我仅使用groovy任务,因为他的语法精巧,可轻松访问ant api,请考虑以下示例:

+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>

您更喜欢哪个?好的,通常代替回声. ...您将使用print或println,
只是为了演示对ant api的访问.

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.

这篇关于Ant中的Groovy脚本:使用脚本任务还是groovy任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆