Apache Ivy 简明教程
Apache IVY - Resolve Task
解析任务用于解析 ivy.xml 中描述的依赖项,下载并将它们放入 ivy 缓存中。
Resolve task is used to resolve dependencies described in ivy.xml, download and put them in ivy cache.
我们首先在 *E: > ivy > src > com > tutorialspoint * 文件夹中创建一个 Java 文件 Tester.java,该文件将充当 ant 项目的源文件夹。
Let’s first create a java file Tester.java in *E: > ivy > src > com > tutorialspoint * folder which will act as source folder for ant project.
Application.java
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 的依赖项部分下定义它。以下是创建的位于 * E: > ivy * 文件夹中的 ivy.xml。
Above class is using apache commons lang library to use its class StringUtils. Ivy should download this library and thus it should be defined under dependencies section in ivy.xml. Following is the ivy.xml created in * E: > ivy * folder.
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>
以下是重要术语。
Following are the important terms.
-
ivy-module − Root element to identify ivy version, namespace etc.
-
info − element to identify the project as a unique entity. organisation − name of the organization module − name of the module status − status like release, integration or milestone.
-
dependencies − element to contain project dependencies as dependency tags which has following attributes. org − name of the dependency’s organization name − name of the dependency. rev − version of the dependency.
build.xml
build.xml
<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve" description="resolve dependencies">
<ivy:resolve />
</target>
</project<
以下是重要术语。
Following are the important terms.
-
project − Root element to identify project name, default task namespace for ivy etc.
-
target − target element to create a new task and its description. This contains an ivy resolve task. When ant builds the project, it runs the ivy resolve task which then resolves the dependencies using ivy.
Building the project
因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。
As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * 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:\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>
Resolve Output
以下是重要术语。
Following are the important terms.
-
conf − configuration, in our case we are using default configuration.
-
modules − indicates the total number of modules, downloaded modules etc.
-
artifacts − indicates the total number of artifacts, downloaded artifacts etc.
你可以在 * ${ivy.default.ivy.user.dir} > .ivy2 > cache* 文件夹中的 Ivy 缓存默认位置验证下载的文件。而 ${ivy.default.ivy.user.dir} 默认为用户主页:$HOME。
You can verify the downloaded files in ivy cache’s default location in * ${ivy.default.ivy.user.dir} > .ivy2 > cache* folder. And ${ivy.default.ivy.user.dir} is by default user home: $HOME.