Convert ivy.xml to pom.xml

What you really need to do is publish the jars built by ANT project into your Maven repository.

ant -Dproject.version=0.9.0-local-20120211095554 clean publish

I know you don’t want to change the ANT build, but creating an extra “publish” target will properly integrate your ANT and Maven projects.

The two jar artifacts, published by your modified ANT build, could be consumed normally as follows:

<dependency>
    <groupId>com.opengamma</groupId>
    <artifactId>og-analytics</artifactId>
    <version>0.9.0-local-20120211095554</version>
</dependency>

<dependency>
    <groupId>com.opengamma</groupId>
    <artifactId>og-analytics</artifactId>
    <version>0.9.0-local-20120211095554</version>
    <classifier>sources</classifier>
</dependency>

Modifications to your ANT build

ivy.xml

Main changes are to your publications section:

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="com.opengamma" module="og-analytics"/>

    <publications>
      <artifact name="og-analytics" type="jar"/>
      <artifact name="og-analytics" type="pom"/>
      <artifact name="og-analytics" type="jar" e:classifier="sources"/>
    </publications>

    <dependencies>
      <dependency name="og-util" rev="0.9.0-local-20120211095525" revConstraint="latest.integration"/>

      <dependency org="org.jfree" name="jfreechart" rev="1.0.13"/>
      <dependency org="cern" name="colt" rev="1.2.0"/>
      <dependency org="cern" name="parallelcolt" rev="0.9.1"/>
      <dependency org="latexlet" name="latexlet" rev="1.11"/>
      <dependency org="org.apache.commons" name="commons-math" rev="2.1"/>

      <dependency org="it.dexy" name="json-doclet" rev="0.3.1"/>
      <dependency org="org.json" name="simple" rev="1.1"/>
      <exclude org="org.junit"/>
    </dependencies>
</ivy-module> 

Notes:

  • The ANT project will now publish 3 files, jar, sources jar and the Maven POM
  • In Maven source jars have a “classifier” attributes that is set to “sources” (Not source). To facilitate this we’re adding an ivy extra attribute.
  • No need for version and status information in the info tag header. This will be added by the publication step.

build.xml

<target name="prepare" description="Generate POM">
    <fail message="Unset property: project.version" unless="project.version"/>

    <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${project.version}" status="release"/>

    <ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/${ivy.module}.pom"/>
</target>

<target name="publish" depends="build,prepare" description="Upload to Nexus">
    <ivy:publish resolver="nexus-deploy" pubrevision="${project.version}" overwrite="true" publishivy="false" >
        <artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
    </ivy:publish>
</target>

Notes:

  • The deliver task is optional, but recommended in case your ivy file contains dynamic revisions, such as “latest.release” or “latest.integration”.
  • The makepoms task has powerful support for convert ivy configurations into Maven scopes. Does not apply in your case, but an incentive to learn more about ivy 🙂
  • The publish task uses a specified pattern to find files specified in ivy’s publications section.

ivysettings.xml

This is where you configure the location of the repositories and credentials to be used by publish build target.

<ivysettings>
    <settings defaultResolver="nexus-central"/>
    <credentials host="somehost" realm="Sonatype Nexus Repository Manager" username="????" passwd="????"/>
    <resolvers>
        <ibiblio name="nexus-central" root="http://somehost/nexus/content/repositories/central/" m2compatible="true"/>
        <ibiblio name="nexus-deploy" root="http://somehost/nexus/content/repositories/repo" m2compatible="true"/>
    </resolvers>
</ivysettings>

Notes:

  • Ivy downloads use the configured default resolver nexus-central.
  • The ivy publish task pushes to the Nexus repository called nexus-deploy
  • The security realm in this example matches Nexus Maven. Would be different for other repo managers.

Leave a Comment