Apache Ivy 简明教程

Apache IVY - Install Task

安装任务用于在解析器中安装模块及其依赖项。当要下载公共构建产出并在私有存储库中使用时,将用到该模块。默认情况下,用户本地存储库就是其私有存储库,位于 ${ivy.default.ivy.user.dir}/local。

Install task is used to install a module and its dependencies in a resolver. It is used when a public artifact is to be downloaded and used in private repository. By default, a user local repository is his/her private repository and is present in ${ivy.default.ivy.user.dir}/local.

让我们按照 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 install 任务。

Update the build.xml to use the ivy install 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 />
   </target>
   <target name="install" description="install dependencies">
      <ivy:install organisation="commons-lang" module="commons-lang"
         revision="2.6" transitive="true" overwrite="false"
         from="public" to="local" />
   </target>
</project>

以下是重要术语。

Following are the important terms.

  1. organisation − name of the organization.

  2. module − module name of the project.

  3. revision − version of the project.

  4. from − from repository type.

  5. to − to repository type.

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 install

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

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

E:\ivy > ant install
Buildfile: E:\ivy\build.xml

install:
[ivy:install] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:install] :: 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:install] :: installing commons-lang#commons-lang;2.6 ::
[ivy:install] :: resolving dependencies ::
[ivy:install]   found commons-lang#commons-lang;2.6 in public
[ivy:install]   found junit#junit;3.8.1 in public
[ivy:install] :: downloading artifacts to cache ::
[ivy:install] :: installing in local ::
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\sources\commons-lang.jar
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\jars\commons-lang.jar
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\javadocs\commons-lang.jar
[ivy:install]   published ivy to C:\Users\Acer\.ivy2\local\commons-lang\commons-
lang\2.6.part\ivys\ivy.xml
[ivy:install]   publish committed: moved C:\Users\Acer\.ivy2\local\commons-lang\
commons-lang\2.6.part
[ivy:install]           to C:\Users\Acer\.ivy2\local\commons-lang\commons-lang\2
.6
[ivy:install]   published junit to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1.p
art\jars\junit.jar
[ivy:install]   published ivy to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1.par
t\ivys\ivy.xml
[ivy:install]   publish committed: moved C:\Users\Acer\.ivy2\local\junit\junit\3
.8.1.part
[ivy:install]           to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1
[ivy:install] :: install resolution report ::
[ivy:install] :: resolution report :: resolve 0ms :: artifacts dl 21ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   0   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 43 seconds

可以在 ivy 缓存的默认本地存储库位置 ${ivy.default.ivy.user.dir}> .ivy2 > local 目录中验证下载的文件。

You can verify the downloaded files in ivy cache’s default local repository location * ${ivy.default.ivy.user.dir} > .ivy2 > local* directory.