Apache IVY - Cachepath Task


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.


<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 name="compile" depends="resolve" description="Compile">
      <mkdir dir="build/classes" />
      <javac srcdir="src" destdir="build/classes">
         <classpath refid="new.classpath" />

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.

Building the project

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

[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
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;working@Acer-
[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   |

   [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

Total time: 3 seconds

You can verify the compiled class file in project build directory.