使用ant任务编译Groovy文件

emi*_*lan 4 java ant groovy javac

我不明白为什么groovy.compile任务在我尝试运行编译任务时运行.

<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
    <classpath>
        <path refid="compile.classpath"/>
    </classpath>
</taskdef>

<target name="groovy.compile">
    <groovyc srcdir="src/groovytest" destdir="bin/classes"/>
</target>

<target name="compile" description="Compile *.java file" depends="init, groovy.compile">
    <javac srcdir="src" destdir="bin/classes" debug="on" deprecation="true">
        <classpath refid="compile.classpath"/>
    </javac>
</target>
Run Code Online (Sandbox Code Playgroud)

有没有办法用javac ant任务而不是groovyc ant任务编译.groovy?

tim*_*tes 12

不,您需要使用该groovyc任务,但是,您应该能够通过执行以下操作来使用联合编译器:

<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
    <classpath>
        <path refid="compile.classpath"/>
    </classpath>
</taskdef>

<target name="compile" description="Compile both groovy and java files" depends="init">
    <groovyc srcdir="src" destdir="bin/classes">
        <javac debug="on" deprecation="true"/>
    </groovyc>
</target>
Run Code Online (Sandbox Code Playgroud)