【问题标题】:Error with self-bootstrapping Ant build自引导 Ant 构建出错
【发布时间】:2013-06-17 15:47:32
【问题描述】:

我正在尝试编写一个 Ant 构建,它需要我将 Ant 插件添加到 Ant 的 lib 目录或 /home/myuser/.ant/lib,或在我的 Eclipse 实例的 ant home 等中;即因为我最终将在托管的 Jenkins 服务器上构建我的项目,我无法访问系统的 Ant 安装。

我将其称为“自引导”构建,因为我使用 Ivy 在构建时拉下我的 Ant 插件,并希望通过一些适当的配置,使它们的任务动态地可供 Ant 使用。

我构建的 jist(以 ant-contrib 插件为例:

<?xml version="1.0" encoding="utf-8" ?>
<project name="myapp" default="audit" basedir="."
        xmlns:ivy="antlib:org.apache.ivy.ant"
        xmlns:antcontrib="antlib:net.sf.antcontrib">

    <!-- Build path. -->
    <path id="build.path">
        <fileset dir="${lib.buildtime.dir}" includes="**/*.jar"/>
    </path>

    <target name="bootstrap">
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
            uri="antlib:org.apache.ivy.ant" classpathref="build.path"/>
    </target>

    <target name="resolve" depends="bootstrap">
        <ivy:settings url="${ivy.settings.home}"/>

        <ivy:cleancache/>

        <ivy:resolve file="${ivy.xml}"/>

        <ivy:retrieve pattern="${gen.lib.main.dir}/[artifact]-[revision].[ext]" conf="main"/>
        <ivy:retrieve pattern="${gen.lib.test.dir}/[artifact]-[revision].[ext]" conf="test"/>
        <ivy:retrieve pattern="${gen.lib.buildtime.dir}/[artifact]-[revision].[ext]" conf="buildtime"/>

        <ivy:report todir="${gen.staging.dir}" />

        <ivy:cachepath pathid="build.path" conf="buildtime"/>
    </target>

    <target name="taskdefs" depends="resolve">
        <taskdef resource="/net/sf/antcontrib/antlib.xml"
            uri="antlib:net.sf.antcontrib" classpathref="build.path"/>

        <property name="fizz" value="buzz" />

        <antcontrib:if>
            <antcontrib:equals arg1="${fizz}" arg2="buzz" />
            <antcontrib:then>
                <echo message="Fizz is buzz!" />
            </antcontrib:then>
            <antcontrib:else>
                <echo message="Fizz is not buzz!" />
            </antcontrib:else>
        </antcontrib:if>
    </target>
</project>

当我运行 taskdefs 目标时,我在 Ant 输出中没有看到回显的“Fizz is buzz!”消息,而是收到以下错误:

BUILD FAILED
/home/myuser/eclipse/workspace/myapp/build.xml:169: Problem: failed to create task or type antlib:net.sf.antcontrib:if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
    -/home/myuser/eclipse/plugins/org.apache.ant_1.8.3.v201301120609/lib
    -/home/myuser/.ant/lib
    -a directory added on the command line with the -lib argument

我正在尝试做的事情(避免必须做上面推荐的 3 件事中的 1 件事)是不可能的吗?如果是这样,为什么?如果不是,我的设置有什么问题?提前致谢!

【问题讨论】:

    标签: java eclipse plugins ant ant-contrib


    【解决方案1】:

    我通常创建一个“boostrap”目标并使用它来将 ivy 安装到“$HOME/.ant/lib”目录中。见:

    以下是一个更完整的示例,可以满足您的要求:

    总之,很遗憾 ivy 默认情况下没有与 ANT 打包。如果您发现您的托管服务阻止您将文件复制到主目录中,那么最简单的做法可能是将 ivy jar 的副本与您的源一起提供(并使用 taskdef 启用它)

    更新

    对 ant-contrib 使用以下 taskdef:

    <taskdef uri="antlib:net.sf.antcontrib" classpathref="build.path"/>
    

    homepage 需要更新。在最近的某个阶段,该库被重新打包为antlib

    【讨论】:

    • 感谢一百万 @Mark O'Connor (+1) - 所以我非常仔细地阅读了这两个链接并且相信我正在做第二个链接推荐的所有事情,并且仍然得到完全相同的构建错误。我已经更新了我的原始帖子以包含我的所有构建目标,直到导致错误的那个目标。 你能看出我哪里出错了吗?再次感谢!
    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多