Apache IVY - Retrieve Task


retrieve task is used to resolve dependencies to a specified location in project workspace.

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:retrieve sync="true" type="jar" />

Following are the important terms.

  • sync − sync true ensure that lib directory is up-to-date and any extra file gets deleted.

  • type − type directs ivy to copy only specified type of artifacts like jar. Source jar, javadoc jar will be ignored. type for source jar is src or source and doc or bundle for javadoc jar.

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

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 316ms :: artifacts dl 18ms
      |                  |            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/2756ms)

Total time: 31 seconds

You can verify the downloaded files in project lib directory.