Tuesday, March 1, 2011

Groovy in Ant build.xml (with Java classes)

I have to include Groovy classes into existing Java apps , and include Groovy into Ant build.xml file. What is the best way to configure Ant build.xml for it?

Thanks Tatyana

I was suggested to update my question, but I am not exactly sure what it means. Tatyana

Urs Reupke wrote: Please update your question to help future answers become more helpful. – Urs Reupke

From stackoverflow
  • To use Groovy in your ant script, you basically have to declare the Groovy ant task:

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

  • @VonC is correct about including Groovy scripting in your Ant build.

    To expand a bit:

    To compile .groovy and .java sources together for use in the same application, use the <groovyc> Ant task.

    See Ant Integration with Groovy for the reference.

  • Are there more specifics in combining Java and Groovy compilations? Sequence of tasks?

    Ken Gentle : groovyc will compile groovy and java source (first groovy to java, then compile all java files if you want to look at it that way.) so you don't need another step. Or you can separate the java compilation from the groovy and include the compiled/jar-ed classes in the groovyc task.
    Urs Reupke : Please update your question to help future answers become more helpful.

0 comments:

Post a Comment