Ant in Action读书笔记(五):如何在Ant里运行Groovy脚本

Groovy作为JVM之上的一种Script语言,越来越流行了。很自然的会想到他能不能跟Ant能集成起来一起发挥功效。

答案是:Yes

你需要先把Groovy安装目录下(C:\Groovy\Groovy-2.0.1\embeddable)groovy-all-xxx.jar拷贝到Ant的lib目录下。

然后我们就可以在build.xml中使用Ant了

第一步 taskdef引用Groovy的类库

   <taskdef name="groovy"  classname="org.codehaus.groovy.ant.Groovy"/>

第二步 定义一个Target,使用Groovy 

<target name="init">
  <property name="version" value="2"/>


  <groovy>
     myversion = properties['version']
     ant.echo myversion
     properties['isGreater']= myversion>1
  </groovy>

  <echo message="${isGreater}"/>
</target>


 上面的示例中既有Groovy使用Ant定义的property,也有在Groovy脚本里新生成一个Ant的property。

NOTE:  Ant的版本要是1.7或以上的

Link: http://groovy.codehaus.org/The+groovy+Ant+Task
 

原文地址:https://www.cnblogs.com/buhaiqing/p/2752153.html