ivy中文参考文档(15)-ant任务(3)-retrieve

本文介绍Ivy中的retrieve任务,用于复制解析后的依赖到指定位置。文章详细解释了retrieve任务的各种属性,如pattern、sync等,并通过示例展示了如何使用这些属性来定制依赖的复制过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1) retrieve

    retrieve任务复制解析好的依赖到你的文件系统的任何位置。

    这是一个post resolve任务,带有所有post resolve任务共有的所有的行为和属性。

    从1.4起 这个任务甚至可以根据依赖解析的结果用实际应该存在的东西来同步目标目录。这意味着如果设置sync为"true",ivy不仅将复制必要的文件,而且它还会删除那些不再需要在那里的文件。

    同步实际上是删除root目标目录下不再是retrieve任务必须的所有文件和目录。

    root目标目录是 在目标正则表达式中的标示为第一级别的第一个标记的目录。
    例如:
    pattern: lib/[conf]/[artifact].[ext]
    root: lib

2) 属性

属性描述必要
patternthe pattern to use to copy the dependencies
用来复制依赖的正则表达式
No. 默认为 ${ivy.retrieve.pattern}
ivypatternthe pattern to use to copy the ivy files of dependencies since 1.3
从1.3起用来复制依赖的ivy文件的正则表达式
No. 默认不获取依赖的ivy文件
confa comma separated list of the configurations to retrieve
用于获取的配置的列表,逗号分隔
No.  默认为被最后一次resolve调用解析好的配置,或者在没有显示调用resoleve时的*
synctrue to synchronize the destination, false to just make a copy since 1.4
从1.4起 true 同步目录路径,false仅仅复制
No. 默认为 false
typecomma separated list of accepted artifact types since 1.4
从1.4起 可接受的制品类型列表,逗号分隔
No. 默认所有制品类型都被接受
symlinktrue to create symbolic links, false to copy the artifacts. The destination of the symbolic links depends on the value of the useOrigin attribute (since 2.0)
true 创建符号链接,false复制制品。符号链接的目的地取决于useOrigin属性的值(从2.0起)
No. 默认为 false
settingsRefA reference to the ivy settings that must be used by this task (since 2.0)
必须被这次任务使用的iry设置的引用
No, 默认使用'ivy.instance'
logthe log setting to use during the resolve and retrieve process. (since 2.0)
Available options are the same as for resolve when used to trigger resolve automatically (see postresolvetask ), or the following for the retrieve process only:
  • default the default log settings, where all usual messages are output to the console
  • quiet disable all usual messages, making the whole retrieve process quiet unless errors occur
No, defaults to 'default'.



3) 示例

1.

< ivy:retrieve  />

    使用默认参数获取依赖。这通常获取最后一次解析调用的所有依赖到lib目录中。

2.

< ivy:retrieve  pattern ="${lib.dir}/[conf]/[artifact].[ext]" />

    获取最后一次解析调用的所有依赖到lib目录中,依赖将分隔在按照组织命名的目录中,每个conf目录包含对应的不带修订版本的制品。

    例如,如果ivy文件声明了两个配置default和test,结果lib目录将会像这样:

lib
  default
    commons-lang.jar
    commons-logging.jar
  test
    junit.jar

    注意如果一个依赖被两个配置要求,它将被复制到两个目录中。这个依赖的下载将只在resolve的时候进行一次。

3.

< ivy:retrieve  pattern ="${lib.dir}/[conf]/[artifact].[ext]"  sync ="true"   />

    和前面相同,但是开启同步。

    例如,如果ivy文件声明了两个配置default和test,结果lib目录将会像这样:

lib
  default
    commons-lang.jar
    commons-logging.jar
  test
    junit.jar

    现在假设commons-logging 不再是默认配置的一部分,然后新的retrieve调用将会产生如下结果:

lib
  default
    commons-lang.jar
  test
    junit.jar

    如果不开启同步,commons-logging将不会被这次调用删除。

4.

< ivy:retrieve  pattern ="${lib.dir}/[type]/[artifact]-[revision].[ext]"  conf ="runtime" />


    仅仅获取配置runtime依赖到用制品类型命名的目录中。结果lib目录将类似这样:

lib
  jar
    commons-lang-1.0.jar
    looks-1.1.jar
  source
    looks-1.1.zip


5.

< ivy:retrieve  organisation ="foo"  module ="bar"  inline ="true"  pattern ="${my.install.dir}/[artifact].[ext]" />


    解析并获取模块bar和它的依赖的最新版本到${my.install.dir}指出的目录。

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值