Antlibs and Classloaders

Stefan Bodewig <[email protected]> Sat, 01 Aug 2026 11:36:54 +0200
Newsgroups gmane.comp.jakarta.ant.devel
Message-ID <[email protected]>
Hi

I'm working on Ivy integration into the CycloneDX Antlib, my goal is to
create the "components" of an SBOM and the dependency relations from a
resolved Ivy module. There isn't anything I can show, yet, but I'm
facing a classloader problem that would probably affect more Antlibs if
they were used more.

In a context like the build of the Antlibs ivy.jar is downloaded and
<typedef>fed and then used to download the CycloneDX Antlib (to stick
with my current case) which also uses a <typedef>. This new Antlib now
also needs Ivy.

I want to use the result of an <ivy:resolve> which is stored as a
reference in the current project in the Antlib. But with a setup like
above this doesn't work as the ResolveReport class the project reference
is an instance of has been loaded by a different classloader than the
Ivy classes used by the Antlib. There also is no parent-child
relationship between the classloaders.

As long as Ivy is loaded by the system classloader (or Ant's core
loader) things work fine - this would be the case for Ant's own build in
its current setup.

Right now I'm using an extremely crude workaround that downloads Ivy,
<typedef>s it, Ivy then downlads the Antlib and its dependencies, I
<typedef> the Antlib and give the classloader a name, then I <typedef>
Ivy once again using the same classloader and run <ivy:resolve> a second
time. This is not the way it should be IMHO.

There is a built-in way in Ant, the <classloader> task - something that
is dirty little secret so much that we don't even document it. This
could either be used to inject Ivy into Ant's core loader - or I could
define the classloader for the Antlib and set it up to use the
classloader that is used by Ivy as its parent. This should work. If this
is an approach we want to recommend, we probably should make the task
"official".

Another idea would be to allow <typedef> to optionally specify the
parent classloader. This would allow the setup of the paragraph above
without the use of the classloader task - but requires a change to Ant.

Any other ideas? Any preferences?

Stefan