Apache Ivy 简明教程

Apache IVY - Retrieve Task

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

retrieve task is used to resolve dependencies to a specified location in project workspace.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml, 以使用 ivy retrieve 任务。

Update the build.xml to use the ivy retrieve task.

build.xml

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>

以下是重要术语。

Following are the important terms.

  1. sync − sync true ensure that lib directory is up-to-date and any extra file gets deleted.

  2. type − type directs ivy to copy only specified type of artifacts like jar. Source jar, javadoc jar will be ignored. type for source jar is src or source and doc or bundle for javadoc jar.

在项目 lib 目录中,retrieve 任务默认情况下复制已解析依赖项,且可以通过 pattern 属性更改。

retrieve tasks copies the resolved dependencies in the lib directory of the project by default and can be changed using pattern attribute.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

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 目录中验证下载的文件。

You can verify the downloaded files in project lib directory.