本文介绍了使用 Ivy 在 Ant 构建中设置路径的最低配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用在工件中定义的 Ant 任务.该工件存在于主 Maven 存储库中并具有一些依赖项.

I want to use an Ant task that is defined in an artifact. The artifact exists in the main Maven repositories and has some dependencies.

我想使用 Ivy 和 Ant 来:

I want to use Ivy and Ant to:

  1. 声明对该工件及其传递依赖项的依赖关系,以便在脚本运行时解析它们.
  2. 检索所有 jar 文件作为 Ant 路径,我可以将其输入 Ant 的 taskdef.
  3. 在构建脚本的其他部分中引用那组已解析的 jar 文件.

到目前为止,我发现的文档并未针对此用例进行优化.相反,它建议编写文件ivy.xml、ivysettings.xml;我不喜欢那样,依赖项太小了,我想把所有东西都放在一个构建脚本中.

So far, the documentation I have found does not optimize for this use case. Instead, it suggests to write the files ivy.xml, ivysettings.xml; I don't like that, the dependencies are small enough that I would like to fit everything in a single build script.

有什么想法吗?

推荐答案

常春藤cachepath 任务 是一个解析任务,可用于创建 ANT 路径.可能不太为人所知的是,这个解析任务也可以内联使用,换句话说,您可以直接指定依赖项,而无需 ivy 文件.

The ivy cachepath task is a resolve task that can be used to create an ANT path. What is perhaps not well known is that this resolving task can also be used inline, in other words, you can specify the dependencies directly without an ivy file.

<ivy:cachepath pathid="tasks.path">
    <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>

对于利用常春藤文件管理多个类路径的相关答案:

For a related answer that utilizes an ivy file to manage multiple classpaths:

下面的例子有点人为地展示了ivy下载与groovy任务相关的jar.我还包含了一个用于安装 ivy jar 的实用程序目标.

The following example is a little contrived by demonstrates ivy downloading the jar associated with the groovy task. I have also included a utility target that I use to install the ivy jar as well.

<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <available classname="org.apache.ivy.Main" property="ivy.installed"/> 

    <!--
    ============
    Main targets 
    ============
    -->
    <target name="resolve" depends="install-ivy">
        <ivy:cachepath pathid="tasks.path">
            <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
        </ivy:cachepath>
    </target>

    <target name="build" depends="resolve">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="tasks.path"/>

        <groovy>
          ant.echo "Hello world"
        </groovy>
    </target>

    <!--
    ==================
    Supporting targets
    ==================
    -->
    <target name="install-ivy" description="Install ivy" unless="ivy.installed">
        <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.4.0/ivy-2.4.0.jar"/>
        <fail message="Ivy has been installed. Run the build again"/>
    </target>

    <target name="clean" description="Cleanup build files">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
        <ivy:cleancache/>
    </target>

</project>

这篇关于使用 Ivy 在 Ant 构建中设置路径的最低配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 06:29