wikipedia

Support Wikipedia

Sunday, March 18, 2012

Publishing to a branch using Ivy

Ivy off the shelf works fine if you are not dealing with branches. The examples in the samples that can be downloaded don't have much for using branches. That's because branches are optional for Ivy. All it cares about is the module name and revision number for getting the last build number or publishing an artifact to the repository.

If you can live without branches then things are fine with Ivy as a dependency manager. But life is not that simple! Once I started using branches everything went haywire. Because I had not made the configuration changes in all the right places. Having figured it out the hard way, would like to share the list of fixes.
The things to do when configuring ivy for branches are
  •  Include branch attribute in artifact and ivy pattern. Like shown below here
   ivy.artifact.pattern=[organisation]/[module]/[branch]/[revision]/[artifact].[ext]
   ivy.pattern=[organisation]/[module]/[branch]/[revision]/ivy.xml
  • Set default branch attribute in ivysettings file as shown below.
<ivysettings>
  <properties file="ivysettings.properties"/>
  <settings defaultCacheDir="${ivy.settings.dir}/ivy-cache" defaultBranch="trunk" defaultResolver="chain" latest="latest-compatible"/>  
   <resolvers>
      <chain name="chain">
          <url name="projects">
              <artifact pattern="http://buildserver/${repository.dir}/${ivy.artifact.pattern}" />
            <ivy pattern="http://buildserver/${repository.dir}/${ivy.pattern}" />
        </url>
        <ibiblio name="libraries" m2compatible="true" usepoms="false" /> 
        <ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true" />
      </chain>
  </resolvers>
  
</ivysettings> 

  • Specify branch attribute in ivy.xml under the info section.
<ivy-module version="1.0">
    <info 
        organisation="org.coastal"
        module="mymodule"
        branch="RB-1.0.0"
        status="integration"
        revision="1.0"/>

    <publications/>
    <dependencies/>    
</ivy-module> 

  • Make sure the buildnumber ivy target has branch parameter too. Like shown below.
<target name="ivy-new-version" depends="" unless="ivy.new.revision">
 <!-- default module version prefix value -->
 <property name="module.version.prefix" value="${ivy.revision}." />
 
 <!-- gets next version number from ivy repository -->
 <ivy:info file="${ivy.file}" />

 <ivy:buildnumber 
  organisation="${ivy.organisation}" module="${ivy.module}" 
  branch="${ivy.branch}"
  revision="${module.version.prefix}" defaultBuildNumber="1" revSep=""/>
</target>

  • The publish ivy target has branch attribute as well.
<target name="publish-remote" depends="build" description="--> publish this project to ivy repository">
    <ivy:publish artifactspattern="${dist.dir}/[artifact].[ext]" 
           resolver="projects"
           pubrevision="${version}" 
           pubbranch="${ivy.branch}"
           update="true"
           status="${ivy.status}"
    />
<echo message="project ${ant.project.name} released with version ${version}" />
</target>