我正在尝试编写一个Ant构建,不要求我将Ant-plugins添加到Ant的lib目录,或/home/myuser/.ant/lib
,或者在我的Eclipse实例的ant home等中;因为我最终将在托管的Jenkins服务器上构建我的项目,在那里我无法访问系统的Ant安装。
我称之为“自引导”构建,因为我在构建时使用Ivy来下载我的Ant插件,并希望通过一些正确的配置,使其动态可用于Ant。
我的构建的主旨(使用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个)是不可能的?如果是这样,为什么?如果没有,我的设置有什么问题?提前谢谢!
答案 0 :(得分:1)
我通常会创建一个“boostrap”目标,并使用它将常春藤安装到“$ HOME / .ant / lib”目录中。参见:
以下是一个更完整的示例,可以执行您要执行的操作:
总之,使用ANT默认情况下不会打包常春藤。如果您发现您的托管服务阻止您将文件复制到主目录中,那么最简单的事情就是在您的源旁边发送常春藤罐的副本(并使用taskdef启用它)
对ant-contrib使用以下taskdef:
<taskdef uri="antlib:net.sf.antcontrib" classpathref="build.path"/>