Apache Ivy 简明教程

Apache IVY - Resolvers

解析器用于查找下载信息库的位置。依赖关系解析器还处理常见任务。Ivy 提供了两种类型的解析器。

Resolvers are used to find locations from where a library is to be downloaded. A dependency resolver also handles common tasks. Ivy provides two types of Resolvers.

  1. Composite − A resolver which uses other resolvers to do its tasks.

  2. Standard − A resolver performs the required tasks.

Standard Resolvers

下表列出了标准解析器及其用法。

Following table lists down the standard resolvers and their usage.

Sr.No.

Name (Type) & Description

1

IvyRep (Standard) Locates Ivy files on ivyrep and artifacts on ibiblio.

2

IBiblio (Standard) Locates artifacts on ibiblio.

3

BinTray (Standard) Locates artifacts on bintray.

4

Packager (Standard) Locates Ivy files and packaging instructions via URLs, creates artifacts using instructions.

5

FileSystem (Standard) Locates Ivy files and artifacts on local file system.

6

URL (Standard) Locates Ivy files and artifacts on repositories which can be accessed using URLs.

7

MirroredURL (Standard) Locates Ivy files and artifacts on repositories which can be accessed using URLs from a mirror list.

8

VFS (Standard) Locates Ivy files and artifacts on repositories which can be accessed using Apache Commons VFS.

9

SSH (Standard) Locates Ivy files and artifacts on repositories which can be accessed using SSH.

10

SFTP (Standard) Locates Ivy files and artifacts on repositories which can be accessed using SFTP.

11

Jar (Standard) Locates Ivy files and artifacts on repositories within a jar.

12

Chain (Composite) Delegates the search to a chain of sub resolvers.

13

Dual (Composite) Delegates the search to a one resolver and artifacts to another.

14

OBR (Standard) Resolve modules as OSGi bundles listed by an OSGi obr.xml.

15

Eclipse updatesite (Standard) Resolve modules as OSGi bundles which are hosted on an Eclipse update site.

16

OSGi-agg (Composite) Delegates the search to a chain of sub resolvers supporting OSGi bundles.

让我们在 E: > ivy2 文件夹如下所描述类似的新项目中创建 Tester.java、build.xml 和 ivy.xml。在 E: > ivy2 下创建一个 settings 文件夹。在 settings 文件夹中创建 ivysettings.xml。

Let’s create Tester.java, build.xml and ivy.xml in a new project under E: > ivy2 folder similar to as described in IVY - Resolve Task chapter. Create a settings folder under E: > ivy2. Create the ivysettings.xml in the settings folder.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <property name = "base.dir" value = ""/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name="compile" depends="resolve" description="Compile">
      <mkdir dir="build/classes" />
      <javac srcdir="src" destdir="build/classes">
         <classpath refid="new.classpath" />
      </javac>
   </target>
</project>

ivy.xml

ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
   <info organisation="org.apache" module="chained-resolvers"/>
   <dependencies>
      <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default"/>
      <dependency org="com.tutorialspoint" name="test" rev="1.0"/>
   </dependencies>
</ivy-module>

在这里,我们添加了两个依赖项,一个用于 commons-lang 库,另一个用于我们在 IVY - Publish Task 章节中发布的测试。

Here we’ve added two dependencies,one of commons-lang library and another as test which we published in IVY - Publish Task chapter.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="multiresolver"/>
   <resolvers>
      <chain name="multiresolver">
         <filesystem name="libraries">
            <artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]"/>
         </filesystem>
         <ibiblio name="ibiblio" m2compatible="true"/>
      </chain>
   </resolvers>
</ivysettings>

在这里,我们添加了使用 chain resolver 创建的一个复合解析器,它有两个解析器,一个名为 library,用于在本地存储库中定位库,一个名为 ibiblio,用于在 maven 公共存储库中定位库。

Here we’ve added created a composite resolver using chain resolver which has two resolver, one named libraries to locate libaries on local repository and one named ibiblio on maven public repository.

Building the project

当我们准备好了所有文件。只需进入控制台。导航到 E: > ivy2 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy2 * 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:\ivy2\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 :: org.apache#chained-resolvers;working@
Acer-PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found com.tutorialspoint#test;1.0 in local
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] downloading C:\Users\Acer\.ivy2\local\com.tutorialspoint\test\1.0\
jars\application.jar ...
[ivy:resolve] .. (1kB)
[ivy:resolve] .. (0kB)
[ivy:resolve]   [SUCCESSFUL ] com.tutorialspoint#test;1.0!application.jar (13ms)

[ivy:resolve] :: resolution report :: resolve 1085ms :: artifacts dl 22ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   3   |   3   |   1   |   0   ||   5   |   1   |
      ---------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 9 seconds

在日志中你可以验证我们同时使用了本地和公共存储库解析器。

In the logs you can verify that we have used both local and public repository resolvers.