Skip to main content

Accessing java.net maven repository from Ivy

Posted by kohsuke on June 11, 2007 at 5:57 PM PDT

Ivy is an increasingly popular dependency management tool. It lets your (Ant) build script downloads library jars from other places, much like Maven. The part that I like about Ivy is that it doesn't try to be everything, unlike Maven. Since I just wasted almost 3 hours trying to get the maven-assembly-plugin to create a convenient all-in-one JAX-WS commons bundle (and in the end blocked by this silly bug), I decided to try Ivy.

Ivy comes out-of-the-box with an implementation that lets you pull jar files from any Maven2 repository, so all the artifacts of our java.net M2 repository are available to the Ivy users. But unfortunately, there's no code to support our java.net Maven1 repository. This is quite unfortunate, as our Maven1 repository hosts a lot of interesteing Sun jars that are not available elsewhere.

So I created one to solve the problem, which brings me to the main point of this post. What this little jar enables you to do is to pick up artifacts from the java.net Maven1 repository, and use its POMs to resolve transitive dependencies automatically. You can download the jar from the link above.

To use this, you'll first create ivysettings.xml (in your project) and define where the repositories are. The following example uses the java.net M1/2 repo and ibiblio, in a sequential fashion (so if an artifact you are looking for is available in any one of those places, you'll be OK)

<br /><ivysettings><br />  <conf defaultResolver="chained"/><br />  <typedef name="java.net" classname="org.jvnet.maven_repository.JavaNetResolver" /><br />  <resolvers><br />    <chain name="chained"><br />      <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/><br />      <java.net name="java.net1" /><br />      <ibiblio name="ibiblio"/><br />    </chain><br />  </resolvers><br /></ivysettings><br />

This is a sample ivy.xml file that describes the dependencies. The stax-ex dependency is actually a transitive dependency from the JAX-WS RI jar, but due to a bug in the stax-ex 1.0 POM, I had to set explicit dependency to 1.1.

<br /><ivy-module version="1.0"><br />    <info organisation="org.jvnet.jax-ws-commons" module="jax-ws-commons-bundle" /><br />    <dependencies><br />        <dependency org="org.jvnet.staxex" name="stax-ex" rev="1.1" /><br />        <dependency org="com.sun.xml.ws" name="jaxws-rt" rev="2.1.1" /><br />    </dependencies><br /></ivy-module><br />

And now here is the build script that shows how to hook this up all together. When you run it, you'll get all the transitive dependencies of the JAX-WS RI 2.1.1 in the lib directory.

<br /><project xmlns:ivy="antlib:org.apache.ivy.ant" name="jax-ws-commons-bundle" default="run"><br />    <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant"><br />        <classpath><br />            <fileset dir="." includes="*.jar" /><br />        </classpath><br />    </taskdef><br /><br />    <target name="resolve"><br />        <ivy:configure file="ivysettings.xml" /><br />        <ivy:retrieve /><br />    </target><br /></project>

If you are interested, the complete example is available. This is my first exposure to Ivy, so if I'm doing things in a wrong/redundant way, please let me know.

Related Topics >>