Sunday, September 18, 2011

Configure ivy to use local Maven repository

This post shows how to configure ivy to use specific local Maven repository.

1) Add following config as a child element of tag "resolvers" in you ivy settings file:

    <filesystem name="local-maven-2" m2compatible="true" force="false" local="true">
       <artifact pattern="${gerald.repo.dir}/[organisation]/[module]/[revision]/[module]-[revision].[ext]"/>
       <ivy pattern="${gerald.repo.dir}/[organisation]/[module]/[revision]/[module]-[revision].pom"/>
    </filesystem>
2) Then add it to your chain resolver config. Example: 
    <chain name="internal" dual="true">
      <resolver ref="local-maven-2"/>
      <resolver ref="apache-snapshot"/> 
      <resolver ref="maven2"/>
    </chain>

If you have multiple resolver chain, make sure that the correct one, which is effective for you build, is changed.

3) After ivy caches the artifacts in its own local repo (the first time the dependency is resolved), it will not pick changes you made to the artifacts in the original Maven repository.  In other words, if you use "mvn clean install" to re-publish the artifact, the new version will NOT propagate to ivy.
You can change the default behavior by tweaking parameters:
    checkmodified, changingPatternchangingMatcher, alwaysCheckExactRevision
Read this article for details: http://ant.apache.org/ivy/history/trunk/settings/resolvers.html
One example:

    <chain name="default" dual="true" 
	     checkmodified="true" changingPattern=".*SNAPSHOT">
     ......
    </chain>

Resources:

http://mail-archives.apache.org/mod_mbox/ant-ivy-user/200807.mbox/raw/%3C94bda3fa0807202250y446a818eodb527dba96c8ac93@mail.gmail.com%3E/