<ivy:publish> task publishes module’s artifacts and resolved descriptor to a repository. It is used to publish our own modules or even modules developed by others which are not available in any repository.
Install v/s Publish
Let’s go through a step-by-step example to understand Apache Ivy Publish task, In the example, instead of live artifacts, we use some dummy files as artifacts. Go ahead and create some dummy artifacts in work dir.
touch simpleivy-jar.jar simpleivy-javadoc.jar simpleivy-source.jar
ivy.xmlalso known as Ivy Descriptor file. Add the following
ivy.xmlto work dir.
<ivy-module version="2.0"> <info organisation="com.xyz" module="simpleivy" /> <publications> <artifact name="simpleivy" type="jar" ext="jar" /> <artifact name="simpleivy" type="javadoc" ext="jar" /> <artifact name="simpleivy" type="source" ext="jar" /> </publications> <dependencies> <dependency org="commons-lang" name="commons-lang" rev="2.6" /> </dependencies> </ivy-module>
<info> – organisation and module name.
<publications> – artifacts of the publish
<artifact> – name, type and ext of the artifact.
<dependencies> – list of dependencies of our module. So, our module requires common-lang 2.6.
build.xml, with a <ivy:publish> task, to work dir.
<project name="localrepository" default="publish" xmlns:ivy="antlib:org.apache.ivy.ant"> <target name="publish" description="Publish this build into repository"> <ivy:resolve/> <ivy:publish pubrevision="1.0" status="release" resolver="local" overwrite="true" > <artifacts pattern="[artifact]-[type].[ext]"/> </ivy:publish> </target> </project>
pubrevision – publication revision. 1.0
status – revision status which may be one of these: integration, milestone and release .
resolver – name of resolver for the publish
artifacts pattern – the pattern to use when search for artifacts mentioned in ivy.xml. Dummy artifacts have simple pattern :
simpleivy-javadoc.jar. It is important to note that, Ivy uses this pattern only to search the artifacts defined in ivy.xml, but not for placing them in the repository. While placing the artifacts in the repository, Ivy uses the pattern provided in the resolver definition for naming the directories and artifacts.
place the module artifacts in the work dir
ivy.xmlwhich provides module info to Ivy.
build.xmlthat contains the <ivy:publish> task
[ivy:publish] :: publishing :: com.xyz#simpleivy [ivy:publish] published simpleivy to /home/m/.ivy2/local/com.xyz/simpleivy/1.0/jars/simpleivy.jar [ivy:publish] published simpleivy to /home/m/.ivy2/local/com.xyz/simpleivy/1.0/javadocs/simpleivy.jar [ivy:publish] published simpleivy to /home/m/.ivy2/local/com.xyz/simpleivy/1.0/sources/simpleivy.jar [ivy:publish] published ivy to /home/m/.ivy2/local/com.xyz/simpleivy/1.0/ivys/ivy.xml
$HOME/.ivy2/local, Publish task creates a directory structure
com.xyz/simpleivy/1.0and under this, it has created four sub-folders: jars, javadocs, sources and ivys. Artifacts lands in first three sub-folders and descriptor file goes into ivys sub-folder. If you analyze the repository layout pattern, it is clear that Ivy has used following patterns, from default local resolver definitions in
/org/apache/ivy/core/settings/ivysettingslocal.xml, to place the files in the local repository.
[organisation]/[module]/[revision]/[type]s/[artifact].[ext]to place ivy.xml
[organisation]/[module]/[revision]/[type]s/[artifact].[ext]to place artifacts
Delivered Ivy Descriptor File
orginal ivy.xml provided by you
ivy-ivy.xml generated by the <ivy:publish>
ivy-ivy.xmlgenerated by <ivy:publish> is the resolved descriptor which is also known as delivered ivy file.