Resolving ASM Dependency Conflicts

Published 04 September 07 05:48 PM | andersnoras 

Yesterday I ran into a rather tricky dependency issue. My final demo for my JavaZone talk depends on both Jen and Hibernate which again depend on different versions of the ASM library. There are quite a few frameworks that rely on this library, so I reckon that this is a rather common problem, but googling for a solution didn’t get me very far so a short post on the subject is in order.

JEN requires version 2.1 of ASM, while Hibernate uses 1.5.3. There are some breaking changes between these, so we’ll need both APIs to build and run the project. Hibernate gets its dependency on ASM via its CGLIB dependency, so the first thing you’ll need to do is to exclude Hibernate’s CGLIB dependency from the POM.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.5.ga</version>
    <exclusions>
        <exclusion>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Hibernate will throw a ClassDefNotFoundException its expected ASM version isn’t in the class path at runtime. Luckily there is a distribution of CGLIB called cglib-nodep which, as the name indicates, has no external dependencies. Hibernate will gladly use this jar instead of the one it depends on so we’ll add a new dependency to the POM.

<dependency>
     <groupId>cglib</groupId>
     <artifactId>cglib-nodep</artifactId>
     <version>2.1_3</version>
</dependency>

Volia, no more ASM dependency headaches.

Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Andris Rauda said on June 19, 2008 9:11 AM:

Worked for me for resolving conflict between OpenEJB 3.0 and Hibernate (added comment for others to be easier to Google this)

Thanks!

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below