Apache IVY - Publish Task


publish task is used to publish current artifacts and its resolved descriptor files to mentioned repository.

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 publish task. First we'll create a jar file and then publish it.


<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   <target name = "jar">
      <jar destfile = "${build.dir}/lib/application.jar"
         basedir = "${build.dir}/classes">      
            <attribute name = "Main-Class" value = "com.tutorialspoint.Application"/>
   <target name="publish" depends="jar">
      <ivy:resolve />
      <ivy:publish resolver="local" pubrevision="1.0" overwrite="true">
         <artifacts pattern="${build.dir}/lib/[artifact].[ext]" />

Following are the important terms.

  • resolver − resolver to be used for publication.

  • pattern − pattern to locate the artifact.

Here publish task first build the jar, then resolve the dependencies, set the information and then publish the artifact to local repository.

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 publish

Ivy will come into action, resolving the dependencies, you will see the following result.

E:\ivy > ant publish
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;1.0.0
[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 121ms :: artifacts dl 15ms
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
[ivy:publish] :: publishing :: com.tutorialspoint#test
[ivy:publish]   published application to C:\Users\Acer\.ivy2\local\com.tutorials
[ivy:publish]   published ivy to C:\Users\Acer\.ivy2\local\com.tutorialspoint\te

Total time: 1 second

You can verify the publish ivy artifacts in local repository.