Apache IVY - Resolve Task



Resolve task is used to resolve dependencies described in ivy.xml, download and put them in ivy cache.

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

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);
   }
}

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

<?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

<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

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

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.

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.

Advertisements