- 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 - 解析任務
Resolve 任務用於解析 ivy.xml 中描述的依賴項,下載並將它們放入 Ivy 快取。
讓我們首先在 **E: > ivy > src > com > tutorialspoint** 資料夾中建立一個 Java 檔案 Tester.java,它將作為 Ant 專案的原始檔夾。
Application.java
package com.tutorialspoint;
import org.apache.commons.lang.StringUtils;
public class Application {
public static void main(String[] args) {
String string = StringUtils.upperCase("Ivy Beginner Guide");
System.out.println(string);
}
}
上面的類使用 Apache Commons Lang 庫來使用其 StringUtils 類。Ivy 應該下載此庫,因此它應該在 ivy.xml 的 dependencies 部分中定義。以下是建立在 **E: > ivy** 資料夾中的 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="com.tutorialspoint"
module="test"
status="integration">
</info>
<dependencies>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.9"/>
</dependencies>
</ivy-module>
以下是重要的術語。
**ivy-module** − 根元素,用於標識 Ivy 版本、名稱空間等。
**info** − 元素,用於標識專案作為一個唯一的實體。
**organisation** − 機構的名稱。
**module** − 模組的名稱。
**status** − 狀態,例如釋出版、整合版或里程碑版。
**dependencies** − 元素,包含專案依賴項作為 dependency 標籤,其具有以下屬性。
**org** − 依賴項的組織名稱。
**name** − 依賴項的名稱。
**rev** − 依賴項的版本。
build.xml
<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve" description="resolve dependencies">
<ivy:resolve />
</target>
</project<
以下是重要的術語。
**project** − 根元素,用於標識專案名稱、Ivy 的預設任務名稱空間等。
**target** − target 元素用於建立一個新的任務及其描述。這包含一個 Ivy resolve 任務。當 Ant 構建專案時,它執行 Ivy resolve 任務,然後使用 Ivy 解析依賴項。
構建專案
我們已經準備好了所有檔案。只需轉到控制檯。導航到 **E: > ivy** 資料夾並執行 ant 命令。
E:\ivy > ant
Ivy 將開始執行,解析依賴項,您將看到以下結果。
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 375ms :: artifacts dl 79ms
---------------------------------------------------------------------
| | 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/101ms)
BUILD SUCCESSFUL
Total time: 1 second
E:\ivy>
解析輸出
以下是重要的術語。
**conf** − 配置,在我們的例子中,我們使用預設配置。
**modules** − 指示模組總數、已下載模組等。
**artifacts** − 指示構件總數、已下載構件等。
您可以在 Ivy 快取的預設位置 **${ivy.default.ivy.user.dir} > .ivy2 > cache** 資料夾中驗證已下載的檔案。而 ${ivy.default.ivy.user.dir} 預設情況下是使用者主目錄:$HOME。