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="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 任務 章節中釋出的 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

您可以在日誌中驗證我們使用了本地和公共倉庫解析器。

廣告
© . All rights reserved.