The Source for Java Technology Collaboration
User: Password:



Kohsuke Kawaguchi

Kohsuke Kawaguchi's Blog

Accessing java.net maven repository from Ivy

Posted by kohsuke on June 11, 2007 at 05:57 PM | Comments (5)

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)


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

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.


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

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.


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

    <target name="resolve">
        <ivy:configure file="ivysettings.xml" />
        <ivy:retrieve />
    </target>
</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.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • It's worth pointing out that you could always pull JARs from maven1 repos using Ivy, you just had to set up your resolver patterns accordingly.

    The key is that you couldn't resolve transitive dependencies from the POMs.

    Posted by: skaffman on June 12, 2007 at 10:39 AM

  • Yes. That's right. Thanks, skaffman.

    Posted by: kohsuke on June 12, 2007 at 11:08 AM

  • Maybe you could try google/fant, although it's not final released, but it's quite straightforward, all dependencies defined in the ant build is in ANT style, no learning curve. and it also leverage the maven repository, and you can define your own private repository also. it also has the pre-defined target, "compile" "test" "coverage" etc.
    So what you really need to define in your project is the project profile(name, id, version) and the dependencies.

    http://code.google.com/p/fant/

    Posted by: maomaode on June 12, 2007 at 06:40 PM

  • how to configure Ivy for Mavane2??

    Posted by: rautrupesh on June 26, 2007 at 12:11 PM

  • Nice blog entry. You may want to mention that your plugin is for the Apache 2.0 alpha version of Ivy, as opposed to the stable version (1.4.1).

    How stable is 2.0?

    Posted by: kito75 on August 08, 2007 at 04:55 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds