Friday, November 11, 2011

Ivy - Custom Configuration

In addition to the Maven Central Repository, let us say we want Ivy to also look up the JBoss public repository at https://repository.jboss.org/nexus/content/repositories/

The best way to configure Ivy is to start with the default configuration and incrementally introduce our changes.

Create a ivysettings.xml in your /confucius directory (i.e. the same directory where you have HelloWorld.java) and make it match the default ivysettings.xml.

Like this:
 <ivysettings>  
  <settings defaultResolver="default"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>  
 </ivysettings>  
   


Next, we will override the default ivysettings-public.xml

We will create our own ivysettings-public.xml in the /confucius directory and point the ivysettings.xml to it.

So your updated ivysettings.xml will look like this:

 <ivysettings>  
  <settings defaultResolver="default"/>  
  <include url="./ivysettings-public.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>  
  <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>  
 </ivysettings>  
   


Now create a ivysettings-public.xml in your /confucius directory and type (or copy-paste) the following in it:

 <ivysettings>  
     <resolvers>  
                 <url name="public">  
                      <artifact pattern="http://repo1.maven.org/maven2/[organization]/[module]/[revision]/[artifact]-[revision].[ext]" />  
                      <artifact pattern="https://repository.jboss.org/nexus/content/repositories/[organization]/[module]/[revision]/[artifact]-[revision].[ext]" />  
                </url>  
     </resolvers>  
 </ivysettings>  
   
   
   


This tells Ivy to use both the Maven central repository and the JBoss public repository when looking for jars.

Note that we have used the 'Url' Resolver - this Resolver looks for jars in any repository accessible with urls.

No comments: