Search code examples
javabuilddependenciesivydependency-management

Ivy - output the results of a resolve to an ivy file


Having resolved my ivy.xml file, I'd like to create a new resolved-ivy.xml file consisting of all of the transitive dependencies found in the resolve. Is it possible to do this?

This is different to a deliver, which (I believe) only writes out the immediate dependencies from your ivy.xml, not the transitive dependencies. The deliver Ant task does have a delivertarget attribute, which looks in the documentation like it should do this. In practice it works only for modules in the same organisation (so not generally for all dependencies) and generates a file per module.

It's also different from the ivy-report XML file that is generated during the resolve, but not hugely different. If what I'm trying is not possible then I'll just hack at this file directly, I suppose.

The context here is trying to enable repeatable reproducible builds, including in the presence of changes (new libraries, versions) to the repository. There are posts around the interwebs that try to do this, and none I've found can do it properly.

  • Additions to the Ivy repository can change resolve results, in particular if any dependencies anywhere in the repository (not just your project) have range dependencies. Example: A depends on B;[2.0,4.0] and B;3.1 is later added to the repository.
  • Idea is to resolve as normal, write the resolve as a flattened Ivy file, save that in your project's VCS for that tag (or whatever) and subsequently resolve against that file with transitive="false". Assuming that existing items in the repository do not change, this allows repeatable builds.
  • If anyone has any better ideas for doing this, I'm all ears. At the moment I'm expecting to have to hack some combination of the ResolveEngine to make the ResolveReport available, then add a custom DeliverEngine to use it.

Solution

  • The feature you are looking for was added in Ivy 2.4: fixdeps. It reads an ivy.xml file, which in this case serves as an specification, and output an equivalent file, e.g. ivy-resolved.xml, with all transitive dependencies resolved.