cachepath task is used to create an ANT classpath with resolved artifacts present in the cache. As ANT needs jars to be classpath to compile java files, Ivy cachepath builds the classpath.
Let's create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.
Update the build.xml to use the ivy retrieve task.
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>
Following are the important terms.
pathid − id of the classpath where cached jars are present.
retrieve tasks copies the resolved dependencies in the lib directory of the project by default and can be changed using pattern attribute.
As we've all the files ready. Just go the console. Navigate to E: > ivy folder and run the ant command.
E:\ivy > ant compile
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.howcodex#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
You can verify the compiled class file in project build directory.