I put together an Ant task(download) that can use the result of the
ivy:resolve task to maintain Eclipse's .classpath file. If your ivy:resolve also generates references to the source jars, this task will also attach them to the corresponding classpath entries in the .classpath file.
To use the class, drop the class on you Ant classpath, then declare the task like so:
<taskdef name="ivyeclipse" classname="org.apache.ivy.ant.EclipseClasspath"/>
It's a standard Ivy post-resolve task. What that means is a) it takes the same common attribute set as any other post-resolve tasks would, and b) it must be run after an ivy:resolve call. For example, every time the following line
<ivyeclipse conf="provided,testtime" />
executes, the entries in .classpath that were generated from the previous run are removed, and new entries added according to the latest ivy:resolve result on ivy conf "provided" and "testtime". The entries generated by this task are marked with an attribute,
ivygen="true", so any entries you manually added are not impacted. Note: if you have added classpath entries manually for the dependencies in ivy.xml, before running this task for the first time ever, it's a good idea to remove all of them, otherwise you'll end up with duplicated entries.
To invoke the source jar attachment support, just add to the ivy.xml references to the source jars. For example:
<dependency org="org.hibernate" name="hibernate-core" rev="3.3.1.GA" conf="compile;references">
<artifact name="hibernate-core" type="sources" ext="jar" m:classifier="sources" conf="references" />
would add hibernate-core's source jar to ivy conf named "references". Then make sure to include conf "references" in the ivy:resolve call, such as:
<ivyeclipse conf="provided,testtime,references" />
The classpath entries updated will then also have the corresponding source jars (if available) attached.