Apache IVY – Resolve Task

Apache IVY - Resolve Task

This topic is about 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 > AdglobΒ folder which will act as source folder for ant project.

Application.java

package com.Adglob;

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.Adglob"
      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.Adglob#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.Adglob#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.

In this topic we learned about Apache IVY – Resolve Task. To know more, Click Here.

This Post Has 6 Comments

Leave a Reply