Apache IVY - resolve 检索任务

检索任务用于将依赖项解析到项目工作区中的指定位置。

让我们按照IVY - 解决任务章节中所述创建 Tester.java、build.xml 和 ivy.xml。

更新 build.xml 以使用 ivy 检索任务。

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
      <ivy:retrieve sync="true" type="jar" />
   </target>
</project>

以下是重要术语。

  • sync − sync true 确保 lib 目录是最新的,并且任何额外的文件都会被删除。

  • type − type 指示 ivy 仅复制指定类型的工件,例如 jar。源 jar、javadoc jar 将被忽略。源 jar 的类型是 src 或 source,javadoc jar 的类型是 doc 或 bundle。

检索任务默认将已解析的依赖项复制到项目的 lib 目录中,并且可以使用模式属性进行更改。

构建项目

我们已经准备好了所有文件。 只需转到控制台即可。 导航至E: > ivy 文件夹并运行 ant 命令。

E:\ivy > ant

Ivy 将开始行动,解决依赖关系,您将看到以下结果。

Buildfile: E:\ivy\build.xml

resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;working@Acer-
PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] :: resolution report :: resolve 316ms :: artifacts dl 18ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: com.tutorialspoint#test [sync]
[ivy:retrieve]  confs: [default]
[ivy:retrieve]  0 artifacts copied, 2 already retrieved (0kB/2756ms)

BUILD SUCCESSFUL
Total time: 31 seconds

您可以在项目lib目录中验证下载的文件。