Apache Ivy Shared Repository


April 4, 2014 Maithilish

6.2. Apache Ivy Shared Repository

Apache Ivy Shared Repository

Shared repository is similar to a local repository in almost all aspects except that all users can access a shared repository and whereas local repository is private to the user who owns it.

Default configuration comes with a resolver named shared which points to $HOME/.ivy2/shared directory. If you don’t like a shared repository in your home directory, then it may be moved to any other locations. Best practice would be to place the it in a directory to which all users or a group of users have read and write access.
Let’s create a shared repository at /opt/ivy/repository/shared
mkdir -p /opt/ivy/repository/shared
chown -R ivy.ivy /opt/ivy
chmod -R 777 /opt/ivy
Repository directory is accessible by all users.
Use following variables to override the default values of shared resolver.
  • ivy.shared.default.root
  • ivy.shared.default.ivy.pattern
  • ivy.shared.default.artifact.pattern
build.xml

<project name="shared repository" default="install" 
 xmlns:ivy="antlib:org.apache.ivy.ant">
 <target name="install" description="--> install modules to shared reporsitory">
  <property name="ivy.shared.default.root" 
         value="/opt/ivy/repository/shared" />
  <ivy:install organisation="commons-lang" module="commons-lang" 
            revision="2.6" transitive="true" overwrite="false" 
            from="public" to="shared" />
 </target>
</project>

Shared repository default root is set through variable ivy.shared.default.root and we set it to /opt/ivy/repository/shared.
To access the shared repository, users have to override ivy.shared.default.root variable in their build files before calling <ivy:resolve>.
Apache Ivy Shared Repository on a Web Server

The above strategy for a shared repository works well when developers have access to the server through telnet. But typically in an enterprise set up, developers work from the desktop and in such a scenario set up a repository accessible over the network .

To serve the shared repository over the network, locate the repository on a web server which runs the http daemon. Create a directory for the repository under Document Root folder of the httpd.
mkdir /var/www/html/ivyrepo
chown apache.apache /var/www/html/ivyrepo
chmod 775 /var/www/html/ivyrepo
usermod -aG apache m # m is username
service httpd start # start the apache web server
In this example, we use Apache HTTP server with its default Document root at /var/www/html. Users who are allowed to install modules are added to apache group and they have to use following build.xml to install the modules.
build.xml

<project name="shared repository" default="install" 
      xmlns:ivy="antlib:org.apache.ivy.ant">
 <target name="install" description="--> install modules to shared reporsitory">
  <property name="ivy.shared.default.root" value="/var/www/html/ivyrepo" />
  <ivy:install organisation="commons-lang" module="commons-lang" 
            revision="2.6" transitive="true" overwrite="false" 
            from="public" to="shared" />
 </target>
</project>

Developers have to use following ivysettings.xml to access the repository from their Desktops.
ivysettings.xml

<ivysettings>
 <property name="web.ivy.pattern" 
              value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" 
              override="false" />
 <property name="web.artifact.pattern" 
              value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" 
              override="false" />
 <settings defaultResolver="chain" />
 <resolvers>
  <chain name="chain">
   <url name="web">
    <ivy pattern="http://localhost/ivyrepo/${web.ivy.pattern}" />
    <artifact pattern="http://localhost/ivyrepo/${web.artifact.pattern}" />
   </url>
   <ibiblio name="public" m2compatible="true" />
  </chain>
 </resolvers>
</ivysettings>

Here we use the URL resolver. Change http://localhost in <ivy> and <artifact> pattern to the URL of the server.
Apache Ivy Repository Managers

To make your shared repository setup more robust, use web based Ivy Repository Managers like Archiva, Artifactory or Nexus. These front ends come with a fine grained security model for repository access by the users.