使用Ivy在Ant构建中设置路径的最低配置? [英] Minimum config to use Ivy to set a path in an Ant build?

查看:62
本文介绍了使用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.

有什么想法吗?

推荐答案

常春藤

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:

以下示例通过演示常春藤下载与groovy任务相关联的jar进行了一些设计.我还包括了一个用于安装常春藤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构建中设置路径的最低配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆