1
votes

I have a project that has two different jars with both containing some of the same classes. What I need is for it to use the classes from Jar "A" before Jar "B". In normal Java compilation (and with Ant), I could specify the order of the classpath itself. This way, I could guarantee that classes in Jar "A" will be used before the classes in Jar "B".

Is there a way to do this in Ivy?

The only way I could think of doing this is to create two separate configurations in my ivy.xml:

<dependency org="com.vegibank" name="a.jar"
    rev="1.0" conf="foo->default"/>

<dependency org="com.vegibank" name="b.jar"
    rev="1.0" conf="compile->default"/>

Then create two separate pathclass references:

<ivy:cachepath pathid="compile.foo.classpath"
    conf="foo"/>
<ivy:cachepath pathid="compile.normal.classpath"
    conf="compile"/>

Then in <javac/>, I could specify the paths:

<javac ...>
    <classpath refid="compile.foo.classpath"/>
    <classpath refid="compile.normal.classpath"/>
</javac>

However, I assume there must be a way to guarantee the way jars are loaded into the classpath when Ivy is doing its resolve.

Is there a way of doing this?

1
Your solution looks good. To be honest I've never been faced with the problem (mixing same classes on the classpath). I'm assuming this is some sort of weird 3rd party packaging issue? - Mark O'Connor
@MarkO'Connor - I ended up doing this the way I mentioned above: Creating a new configuration, so I can force that jar to be first. The developers ended up fixing the problem. The obsolete jar's class treated the method as returning an enumerator and the new jar's class treated the method as returning an iterator. It took a couple of minor changes in two or three source files to fix it. Of course, the developers fixed the issue, but never compiled to make sure it works. It couldn't compile because the obsolete jar's classes were being used. I had to fix my fix. - David W.

1 Answers

1
votes

Every Ivy Ant task and even IvyDE is respecting the order of the declaration of the dependencies in the ivy.xml file. So if in your ivy.xml you declare a dependency on a.jar before b.jar, the resulting classpath will have a.jar first and b.jar after.