Apache Ivy 简明教程
Apache IVY - Cachepath Task
用作创建 ANT 类路径的 cachepath 任务,该类路径包含高速缓存中存在的已解析工件。由于 ANT 需要将 jar 设置为编译 Java 文件的类路径,因此 Ivy cachepath 将构建类路径。
让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。
更新 build.xml, 以使用 ivy retrieve 任务。
build.xml
<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve" description="resolve dependencies">
<ivy:resolve />
<ivy:cachepath pathid="new.classpath" />
</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>
以下是重要术语。
-
pathid − 存在缓存工件的类路径 id。
在项目 lib 目录中,retrieve 任务默认情况下复制已解析依赖项,且可以通过 pattern 属性更改。
Building the project
因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。
E:\ivy > ant compile
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 2314ms :: artifacts dl 15ms
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| default | 2 | 2 | 0 | 0 || 4 | 0 |
---------------------------------------------------------------------
compile:
[javac] E:\ivy\build.xml:13: warning: 'includeantruntime' was not set, defau
lting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to E:\ivy\build\classes
BUILD SUCCESSFUL
Total time: 3 seconds
可以在项目构建目录中验证已编译类文件。