简体   繁体   English

Ant build.xml中的Groovy(带有Java类)

[英]Groovy in Ant build.xml (with Java classes)

I have to include Groovy classes into existing Java apps, and include Groovy into Ant's build.xml file. 我必须将Groovy类包含到现有的Java应用程序中,并将Groovy包含在Ant的build.xml文件中。

What is the best way to configure Ant's build.xml for it? 为它配置Ant的build.xml的最佳方法是什么?

Update: Are there more specifics in combining Java and Groovy compilations? 更新:结合Java和Groovy编译有更多细节吗? Sequence of tasks? 任务顺序?

@VonC is correct about including Groovy scripting in your Ant build. @VonC在Ant构建中包含Groovy脚本是正确的。

To expand a bit: 扩大一点:

To compile .groovy and .java sources together for use in the same application, use the <groovyc> Ant task. 要将.groovy.java一起编译以在同一应用程序中使用,请使用<groovyc> Ant任务。

See Ant Integration with Groovy for the reference. 请参阅Ant与Groovy的集成以供参考。

To use Groovy in your ant script, you basically have to declare the Groovy ant task : 要在您的ant脚本中使用Groovy,您基本上必须声明Groovy ant任务

<project name="groovy-build" default="listSourceFiles">

<taskdef name="groovy"
     classname="org.codehaus.groovy.ant.Groovy"/>
<groovy>
    ant.... // some ant groovy directives
</groovy>
</target>
</project>

However, you have to be careful, in your ant.xml, to refer to fileset within your current target . 但是,您必须在ant.xml中小心引用当前目标中的 fileset。

You should define javac inside groovyc, like this. 你应该在groovyc中定义javac,就像这样。

<groovyc srcdir="${testSourceDirectory}" destdir="${testClassesDirectory}">
  <classpath>
    <pathelement path="${mainClassesDirectory}"/>
    <pathelement path="${testClassesDirectory}"/>
    <path refid="testPath"/>
  </classpath>
  <javac source="1.4" target="1.4" debug="on" />
</groovyc>

For more info have a look here: http://groovy.codehaus.org/The+groovyc+Ant+Task at section Joint Compilation. 有关详细信息,请查看此处: http//groovy.codehaus.org/The+groovyc+Ant+Task在Joint Compilation部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM