Convert Ivy.Xml to Pom.Xml

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.

Maven POM dependencies to ivy.xml file

Here's an Ant script

<project name="convertPomToIvy" basedir="." default="all"
xmlns:ivy="antlib:fr.jayasoft.ivy.ant"
xmlns:ac="antlib:net.sf.antcontrib">

<path id="antlib.classpath">
<fileset dir="/path/to/ivy/libs" includes="*.jar"/>
</path>

<taskdef uri="antlib:fr.jayasoft.ivy.ant"
resource="fr/jayasoft/ivy/ant/antlib.xml"
classpathref="antlib.classpath"
loaderref="antlib.classpath.loader"/>

<target name="convert">
<ivy:convertpom pomFile="pom.xml" ivyFile="ivy.xml" />
</target>

</project>

From here or here (& probably elsewhere)

Trying to convert ivy artifacts into maven - missing artifact exception for the pom, even though it is there

Your publish does not have an artifact pattern that finds the pom generated by your "makepom" task.

Either change the location or alternatively add an extra artifacts tag to your publish task:

<ivy:publish resolver="myrepo-publish" publishivy="false" overwrite="true">
<artifacts pattern="lib/myorg/[module]/[type]s/[artifact].[ext]"/>
<artifacts pattern="${ivy.lib.dir}/ivy/cache/myorg/mystuff.services.common/poms/mystuff.services.common.pom"/>
</ivy:publish>

I also don't understand why you're inserting a POM entry into you ivy file. Why don't you just list in your publications section?

For a detailed example see:

  • how to publish 3rdparty artifacts with ivy and nexus

Can ivy install and retrieve configurations from Maven repository?

Can ivy install and retrieve configurations from Maven repository?

The simple answer is no.

How ivy interprets a Maven repo

Maven does not support Ivy's concept of configurations. The closest comparison would be Maven "scopes". These are fixed and ivy's ibiblio resolver understands how to map these into configuration. The following answer has a more detailed description:

  • How are maven scopes mapped to ivy configurations by ivy

How ivy pushes file into a Maven repo

When publishing an artefact to Maven repository you must also generate the Maven metadata file: pom.xml. The makepom task allows you to specify which ivy configurations should be used for a particular Maven scope. The following answers might prove useful:

  • Convert ivy.xml to pom.xml
  • how to publish 3rdparty artifacts with ivy and nexus
  • Publishing multiple artifacts to maven repository using ivy
  • Ivy makepom marks all dependencies as optional despite mapping

Ivy is not restricted to a fixed number of scopes. While ivy configurations are much more flexible, you cannot assume that each configuration is being use to populate standard project classpaths....

Bulk loading a Maven repo

So in conclusion to bulk transfer files from a local ivy repo to a Maven repository is not a trivial exercise for the following reasons:

  1. Translating ivy files into Maven POMs can be hard. Ivy's configurations do not work exactly the same as Maven scopes.
  2. Your local repository might contain files that are already in Maven Central and so don't really need to be explicitly uploaded.

In my experience the biggest problem is large numbers of 3rd party jars with no record of where they came from. To assist in Maven-izing new projects I developed a groovy script that uses the Nexus search API to find matching records in the Maven Central database. Generally speaking this approach results in a reduction in the number of jars to be locally stored by as much as 80%.

  • https://github.com/myspotontheweb/ant2ivy

Hope this helps.



Related Topics



Leave a reply



Submit