通常,要使 Ivy 任务可用于 Ant 构建,您需要:
- 添加
ivy.jar
至${ANT_HOME}/lib
. - 添加
xmlns:ivy="antlib:org.apache.ivy.ant"
对 build.xml 的<project>
的声明元素。 - 添加
<taskdef>
build.xml 中的声明引用了ivy.jar
的antlib.xml
定义所有其他任务的文件。
除了第一步(将 ivy.jar
添加到 ${ANT_HOME}/lib
),我想完成上述所有操作。我想要 ivy.jar
住在我项目的某个地方,比如说 lib/buildtime/ivy.jar
,并以某种方式引用 lib/buildtime/ivy.jar
Ivy 所在的地方。
这可能吗?如果是这样,如何?如果不是,为什么?提前致谢!
最佳答案
如果 ivy jar 位于标准 ANT 库目录中,则不需要 taskdef(步骤 3)。
我建议包括一个特殊的“bootstrap”目标,它将安装 ivy jar。完成此操作后,所有其他依赖项(包括第 3 方 ANT 任务)都可以作为构建依赖项由 ivy 下载。
这是我的默认构建文件,它演示了这个概念:
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="bootstrap" description="Install ivy">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
</target>
<target name="resolve" description="Use ivy to resolve classpaths">
<ivy:resolve/>
<ivy:report todir='build/ivy-reports' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
</target>
<target name="clean" description="Cleanup build files">
<delete dir="build"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>
注意事项:
- “bootstrap”目标只需要在新的开发环境中运行一次。安装后,ivy jar 可用于所有 future 的 ANT 运行。
- 这个例子没有使用“$ANT_HOME/lib”(你可能没有写权限)。相反,它使用鲜为人知的“$HOME/.ant/lib”目录,其目的相同。
关于java - 如何动态添加Ivy到Ant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947753/