Convert ivy.xml to pom.xml
Asked Answered
A

2

12

I have a ivy.xml - https://gist.github.com/1898060 I also have the jar file related to this ivy.xml. What i need is a mechanism to import this project to my maven repo and use it in my maven project. SO basically if i am able to convert the ivy.xml to pom.xml , i might be able to get it work. Is there some mechanism through which i can achieve this. I am looking for something like a maven plugin to accomplish this task. I know that there are ways we can edit the ivy.xml and build.xml to achieve this but then i dont want to do it , as the project is in a private repo.

Akel answered 24/2, 2012 at 5:46 Comment(0)
V
22

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.
Vardon answered 24/2, 2012 at 10:37 Comment(0)
L
3

Apache Ant itself provides a task to do this - makepom. Always helps to consult the documentation!

Littles answered 24/2, 2012 at 6:27 Comment(3)
I would prefer not to edit build.xml or ivy.xml. I prefer to use some script or tool which will input ivy.xml and the jar and installs the jar with the right pom.xml into local maven repo. OR a tool which can convert local ivy repo to maven repo would be awesome.Akel
@Littles The makepom task is actually part of Apache ivy. Ivy is a sub-project of ANT. For some inexplicable reason the jar is not included in the standard ANT download,Tonsillotomy
Hmm, sorry if my post was unclear, I assumed it was common knowledge to those using Ivy that it is a partvof Ant. @VineethMohan - the makepom task generates a separate POM from your ivy.XML file. But also see the excellent answer from Mark.Littles

© 2022 - 2024 — McMap. All rights reserved.