- 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="https://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。