2

I have a large Ivy project, and Ive noticed that my code, which run well in eclipse, cause a compile error when run in ant. I've narrowed the problem down to the following line :

FileUtils.write(...). 

This line fails - during compilation --- the method is simply not found. Obviously, my code is dependant on apache's commons-io library. And its quite clear that the current commons-io has this method.

http://commons.apache.org/io/apidocs/org/apache/commons/io/FileUtils.html

So what gives ?

I am pretty sure this is related to my ivy.xml -> the eclipse compiler is luckily (or smartly) using the newest possible version of commons-io , whereas my ivy.xml is using an older version which lacks this method.

Most important of all to not here is that ant is clearly using a different version of this jar.

So - my question is :

1) How can I tell ant / ivy to preferentially compile my code with the latest versions of libraries i specify ? I'm assuming that some of the dependencies in my lib/ may depend on older versions of commons-io .....

Also :

2) In this context, any hints about what to worry about regarding the how the classloader deals with duplicates in a multi-jar-dependent project would also be helpful to me ...

jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • Any possibility of switching to Maven? I know having Maven always use the latest version of a dependency is trivial. I'd imagine Ivy has some similar sort of functionality, however. This looks useful: http://stackoverflow.com/questions/2399099/resolving-snapshot-dependencies-with-timestamps-from-ivy – aroth Mar 20 '12 at 06:22
  • 2
    @aroth Switching to Maven is not always an option for large legacy ANT builds. In my experience Maven works best for greenfield projects – Mark O'Connor Mar 20 '12 at 19:27

2 Answers2

3

Dependency Reporting

I would suggest that you first add the generation of an ivy dependency report into your build, using the report task.

An example of this task is included in the following answer:

What is the Ivy equivalent of Maven's versions:display-dependency-updates?

This will tell you what versions of what jars are being used. Normally, ivy will use the version you specify in the ivy.xml file, however, another module might depend on a more recent version. Ivy's default behaviour is to always favour the most recent version of a Maven module.

Retrieve the latest dependency

If you want ivy to always prefer the latest version of a particular library then declare the dependency as follows:

<dependency org="commons-io" name="commons-io" rev="latest.release"/>
Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
1

Ivy has a feature called Fixed and Dynamic Revisions. You can set the version/revision of any artifact to latest-status like

rev="latest.integration" --> for development released
rev="latest.release" --> for released versions

Ivy takes the version with the highest version(you have specified) and omits all libraries with lower versions, so that you only have one lib in the ivy classpath (have a look at the resolution report, run ant -v (verbose mode))., which avoids having duplicate jars with conflicting versions.
This might be worth checking out, maybe you just have an old version defined in one of your ivy files.

As to the second point:

The classloader takes the class, that happens to be first in the classpath(or the jar that is first in the classpath). So mixed versions of the same lib, could behave differently on any system, depending on how the classpath is constructed.

Community
  • 1
  • 1
oers
  • 18,436
  • 13
  • 66
  • 75