1

我有一个 Android 构建脚本。它尝试使用 Gant 任务而不是 Ant 目标来完成项目上的自定义工作。有趣的构建脚本部分如下所示:

<taskdef name="gant" classname="org.codehaus.gant.ant.Gant">
    <classpath>
        <pathelement location="${gant.dir}/gant-1.9.7_groovy-1.8.4.jar" />
    </classpath>
</taskdef>

<target name="-pre-build">
    <gant target="targetA"/>
    <gant target="targetB"/>
    <gant target="targetC"/>
    <gant target="targetD"/>
    <gant target="targetE"/>
</target>

<target name="-pre-compile">
    <gant target="targetF"/>
</target>


我的 build.gant 文件肯定有这些目标,但是当使用 Ant 运行构建脚本时,我得到:

(...)\build.xml:55: java.lang.NoClassDefFoundError: groovy/util/AntBuilder

蚂蚁一上线:

    <gant target="targetA"/>


我使用 Groovy 1.8.4 和从 Windows 安装程序文件安装的 Gant 和带有 Ant 视图的 Eclipse Helios。Gant.dir 属性具有有效路径,因此并非如此。看起来 Groovy 无法在 build.gant 文件中找到目标,即使它们存在。我什至尝试使用提供 build.gant 文件的完整路径的 Gant 任务,但没有成功。从控制台运行 Ant 脚本时也会发生同样的事情。Build.gant 文件在 Ant 脚本中可见。

有没有什么办法解决这一问题?

4

1 回答 1

0

因此,这不是 build.gant 中不可见目标的问题,而是 taskdef 的类路径中缺少库的问题。以下解决了我的问题:

<path id="gant.libs">
    <fileset dir="${gant.libs.dir}" includes="**/*.jar"/>
</path>

<taskdef name="gant" classname="org.codehaus.gant.ant.Gant">
    <classpath refid="gant.libs"/>
</taskdef>

<target name="-pre-build">
    <gant target="targetA"/>
    <gant target="targetB"/>
    <gant target="targetC"/>
    <gant target="targetD"/>
    <gant target="targetE"/>
</target>

<target name="-pre-compile">
    <gant target="targetF"/>
</target>

其中 gant.libs.dir 是指包含 Gant 1.9.7 二进制独立安装 zip 文件中的 gant_groovy1.8-1.9.7.jar 和 groovy-all-1.8.4.jar 的目录。

于 2011-12-07T00:23:55.490 回答