- Apache IVY 教程
- Apache IVY - 首页
- Apache IVY - 概述
- Apache IVY - 环境设置
- Apache IVY - 术语表
- Apache IVY - 设置文件
- Apache IVY - Eclipse Ivy 插件
- ANT Ivy 任务
- Apache IVY - resolve 命令
- Apache IVY - install 命令
- Apache IVY - retrieve 命令
- Apache IVY - cachepath 命令
- Apache IVY - publish 命令
- Apache IVY - info 命令
- 仓库
- Apache IVY - 解析器
- Apache IVY - 本地仓库
- Apache IVY - 共享仓库
- Apache IVY - 公共仓库
- Apache IVY 有用资源
- Apache IVY - 快速指南
- Apache IVY - 有用资源
- Apache IVY - 讨论
Apache IVY - 解析器
解析器用于查找下载库的位置。依赖项解析器还处理常见任务。Ivy 提供两种类型的解析器。
组合型 − 使用其他解析器执行其任务的解析器。
标准型 − 执行所需任务的解析器。
标准解析器
下表列出了标准解析器及其用法。
| 序号 | 名称(类型)&描述 |
|---|---|
| 1 | IvyRep (标准型) 在 ivyrep 上查找 Ivy 文件,在 ibiblio 上查找构件。 |
| 2 | IBiblio (标准型) 在 ibiblio 上查找构件。 |
| 3 | BinTray (标准型) 在 bintray 上查找构件。 |
| 4 | Packager (标准型) 通过 URL 定位 Ivy 文件和打包说明,使用说明创建构件。 |
| 5 | FileSystem (标准型) 在本地文件系统上查找 Ivy 文件和构件。 |
| 6 | URL (标准型) 在可以使用 URL 访问的仓库上查找 Ivy 文件和构件。 |
| 7 | MirroredURL (标准型) 在可以使用 URL 从镜像列表访问的仓库上查找 Ivy 文件和构件。 |
| 8 | VFS (标准型) 在可以使用 Apache Commons VFS 访问的仓库上查找 Ivy 文件和构件。 |
| 9 | SSH (标准型) 在可以使用 SSH 访问的仓库上查找 Ivy 文件和构件。 |
| 10 | SFTP (标准型) 在可以使用 SFTP 访问的仓库上查找 Ivy 文件和构件。 |
| 11 | Jar (标准型) 在 jar 文件内的仓库中查找 Ivy 文件和构件。 |
| 12 | Chain (组合型) 将搜索委托给一系列子解析器。 |
| 13 | Dual (组合型) 将搜索委托给一个解析器,将构件委托给另一个解析器。 |
| 14 | OBR (标准型) 将模块解析为 OSGi obr.xml 中列出的 OSGi 包。 |
| 15 | Eclipse updatesite (标准型) 将模块解析为托管在 Eclipse 更新站点上的 OSGi 包。 |
| 16 | OSGi-agg (组合型) 将搜索委托给一系列支持 OSGi 包的子解析器。 |
让我们在一个新项目(位于 **E:>ivy2** 文件夹下)中创建 Tester.java、build.xml 和 ivy.xml 文件,类似于 IVY - Resolve 任务 章节中所述。在 **E:>ivy2** 文件夹下创建一个 settings 文件夹。在 settings 文件夹中创建 ivysettings.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
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://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 任务 章节中发布的 test。
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 解析器创建了一个组合型解析器,它有两个解析器,一个名为 libraries,用于在本地仓库中查找库;另一个名为 ibiblio,用于在 Maven 公共仓库中查找库。
构建项目
所有文件准备就绪后,进入控制台。导航到 **E:>ivy2** 文件夹,然后运行 ant 命令。
E:\ivy > ant
Ivy 将开始运行,解析依赖项,您将看到以下结果。
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
您可以在日志中验证我们使用了本地和公共仓库解析器。