简体   繁体   English

如何动态添加Ivy到Ant

[英]How to add Ivy to Ant dynamically

Typically, to make Ivy tasks available to an Ant build, you need to: 通常,要使Ivy任务可用于Ant构建,您需要:

  1. Add ivy.jar to ${ANT_HOME}/lib . ivy.jar添加到${ANT_HOME}/lib
  2. Add an xmlns:ivy="antlib:org.apache.ivy.ant" declaration to your build.xml's <project> element. xmlns:ivy="antlib:org.apache.ivy.ant"声明添加到build.xml的<project>元素中。
  3. Add a <taskdef> declaration inside build.xml that reference's the ivy.jar 's antlib.xml file where all other tasks are defined. 在build.xml中添加一个<taskdef>声明,引用ivy.jarantlib.xml文件,其中定义了所有其他任务。

I'd like to accomplish all of the above except the first step (adding ivy.jar to ${ANT_HOME}/lib ). 除了第一步(将ivy.jar添加到${ANT_HOME}/lib之外 ,我想完成上述所有操作。 I'd like to have ivy.jar living somewhere inside my project, say, at lib/buildtime/ivy.jar , and somehow reference lib/buildtime/ivy.jar as where Ivy is located. 我想让ivy.jar住在我的项目中的某个地方,例如,在lib/buildtime/ivy.jar ,并以某种方式引用lib/buildtime/ivy.jar作为Ivy所在的位置。

Is this possible? 这可能吗? If so, how? 如果是这样,怎么样? If not, why? 如果没有,为什么? Thanks in advance! 提前致谢!

The taskdef (step 3) is not required if the ivy jar is located in a standard ANT library directory. 如果常春藤罐位于标准ANT库目录中,则不需要taskdef(步骤3)。

I would recommend including a special "bootstrap" target that will install the ivy jar. 我建议包括一个特殊的“bootstrap”目标,它将安装常春藤罐。 Once this is done all other dependencies (including 3rd party ANT tasks) can be downloaded by ivy as a build dependency. 完成此操作后,ivy可以将所有其他依赖项(包括第三方ANT任务)作为构建依赖项下载。

Here is my default build file that demonstrates the concept: 这是我的默认构建文件,演示了这个概念:

<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>

Notes: 笔记:

  • The "bootstrap" target only needs to be run once on a new development environment. “bootstrap”目标只需要在新的开发环境中运行一次。 Once installed the ivy jar is available to all future ANT runs. 一旦安装,常春藤罐可用于所有未来的ANT运行。
  • This example doesn't use "$ANT_HOME/lib" (which you may not have write permissions for). 此示例不使用“$ ANT_HOME / lib”(您可能没有写入权限)。 Instead it uses the lesser known "$HOME/.ant/lib" directory which serves the same purpose. 相反,它使用鲜为人知的“$ HOME / .ant / lib”目录来实现相同的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM