info task is used to set ivy specific information in a file and can be used without any dependency resolution.
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. Before publish task, we've set the required ivy information using info task.
build.xml
<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> <target name = "jar"> <jar destfile = "${build.dir}/lib/application.jar" basedir = "${build.dir}/classes"> <manifest> <attribute name = "Main-Class" value = "com.howcodex.Application"/> </manifest> </jar> </target> <target name="publish" depends="jar"> <ivy:info file="ivy.xml" /> <ivy:publish resolver="local" pubrevision="1.0" overwrite="true"> <artifacts pattern="${build.dir}/lib/[artifact].[ext]" /> </ivy:publish> </target> </project>
Here publish task first build the jar, then set the information using ivy:info task and then publish the artifact to local repository.
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.
Buildfile: E:\ivy\build.xml jar: publish: [ivy:info] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy/ :: [ivy:info] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14/l ib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml [ivy:publish] :: publishing :: com.howcodex#test [ivy:publish] published application to C:\Users\Acer\.ivy2\local\com.tutorials point\test\1.0\jars\application.jar [ivy:publish] published ivy to C:\Users\Acer\.ivy2\local\com.howcodex\te st\1.0\ivys\ivy.xml BUILD SUCCESSFUL Total time: 0 seconds
If we do not put the info task then publish task will not work. Use the below modified build.xml and see the error for missing organization attribute and so on.
build.xml
<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> <target name = "jar"> <jar destfile = "${build.dir}/lib/application.jar" basedir = "${build.dir}/classes"> <manifest> <attribute name = "Main-Class" value = "com.howcodex.Application"/> </manifest> </jar> </target> <target name="publish" depends="jar"> <ivy:publish resolver="local" pubrevision="1.0" overwrite="true"> <artifacts pattern="${build.dir}/lib/[artifact].[ext]" /> </ivy:publish> </target> </project>
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.
Buildfile: E:\ivy\build.xml jar: publish: [ivy:publish] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy / :: [ivy:publish] :: 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 BUILD FAILED E:\ivy\build.xml:28: no organisation provided for ivy publish task: It can eithe r be set explicitly via the attribute 'organisation' or via 'ivy.organisation' p roperty or a prior call to <resolve/> Total time: 3 seconds