Friday, January 1, 2010

Ivy|Working with Ivy - Artifactory

Working with Ivy - Artifactory - Confluence

Setting up Ivy to work with Artifactory

In order to make Ivy work with Artifactory, the following files must be present and configured:

  1. The Ivy settings - ivysettings.xml - used to configure artifact resolution and deployment using repositories in Artifactory.
  2. The Ivy modules - ivy.xml - where the project's modules and dependencies are declared.
  3. The Ant build - build.xml - which is used to execute the ANT tasks that will, in turn, use Ivy for artifact resolution and deployment.

Ivy Settings - ivysettings.xml

The ivysettings.xml file holds a chain of Ivy resolvers, which are used for both resolution and publishing (deployment). Resolvers exist for both regular artifacts and Ivy module files.
There are a couple of options to set up Ivy to work with Artifactory by configuring resolvers in ivysettings.xml: The ibiblio resolver and the URL resolver.

The iBiblio Resolver

This resolver is used strictly for dependency resolution. By default it assumes artifacts in your repository are laid-out in the popular standard Maven 2 format (which may not always be the case).
The ibiblio resolver can resolve artifacts from remote Maven 2 HTTP repositories, and if you use version ranges it relies on maven-metadata.xml files in the remote repository to gather information on the available versions.
To use the ibiblio resolver add the following to your ivysettings.xml:

<ibiblio name="artifactory" m2compatible="true" root="http://localhost:8080/artifactory/libs-releases"/>
The root URL needs to point at an Artifactory repository. In this case, the pre-configured 'libs-releases' virtual repository.
The m2compatible property pre-configures the resolver with an artifact pattern that follows the Maven 2 standard layout.

The URL Resolver

The URL resolver can be used for dependency resolution and/or deployment of both regular artifacts and Ivy module files.

To publish or resolve artifacts to/from Artifactory configure a URL resolver with the pattern that matches your target repository layout for both Ivy and artifact files, e.g.:

<url name="artifactory-publish">     <!-- You can use  m2compatible="true" instead of specifying your own pattern -->     <artifact pattern=       "http://localhost:8080/artifactory/libs-snapshots-local/\]\[organization\]/\[module\]/\[revision\]/\[artifact\]-\[revision\].\[ext\]"/>     <ivy pattern="http://localhost:8080/[organization]/[module]/[revision]/ivy-[revision].xml" /> </url> 
The URL resolver uses HTML href analysis to learn about the available versions of a remote artifact. This is a less reliable method compared to the ibiblio resolver way, though it works fine with remote Artifactory servers.

Using a Chain Resolver

You can mix resolvers under a chain resolver in Ivy which will use sub-resolvers for dependency resolution and publishing. Please refer to the relevant Ivy documentation.

Ivy Modules - ivy.xml

ivy.xml files contain a list of dependency declarations that are needed to be resolved for the build.
You can use the Artifactory UI to obtain dependency declaration snippets by selecting either an Ivy module or a POM artifact and copying the "Ivy Dependency Declaration" section into your ivy.xml file.

Ant Build - build.xml

To work with Ivy for dependency resolution you need to use <ivy:configure/> in your build.xml file. This will load the ivysettings.xml.
The resolution of artifacts is done using <ivy:retrieve/>.
Please consult the Ivy documentation for more detailed information.

Publishing to Artifactory

In order to publish to Artifactory the <ivy:publish> command needs to be used. Ivy will use the configured resolver to deploy your artifact into Artifactory. For example:

<ivy:publish resolver="artifactory-publish" overwrite="true">    <!--    Use overwrite="true" if you wish to overwrite existing artifacts    and publishivy="false" if you only want to publish artifacts not module descriptors    -->    <artifacts/> </ivy:publish> 

Please consult the Ivy documentation for more detailed information.

Searching the Content of Ivy Modules

You can search the content of Ivy modules in Artifactory.
From Artifacts:POM/XML Search select the name you use for Ivy modules (typically ivy.xml) and use an XPath query to define your search.
For example:

Support for other Ivy file patterns
Though ivy.xml is the common name for Ivy modules, Ivy does not mandate a standard name. Out of the box *.ivy is also supported, and you can instruct Artifactory to index other file patterns by editing the artifactory.xmlAdditionalMimeTypeExtensions property in $ARTIFACTORY_HOME/artifactory.system.properties.
Of course this applies to XML files in general.
Labels parameters

No comments: