Useful classloaders for use in Gradle plugins

I’m in the middle of porting the cal10n-maven-plugin to Gradle. I’m also attempting to give the plugin configuration a more convenient API. As well as being able to list the translation enums as fully qualified classes I’m also about to add an option to allow a package (and it’s sub-packages) to be scanned for translation enums.

I’m positive that Gradle must perform a lot of classloading magic, are there any classloaders that I could re-appropriate for this use? I’m especially interested in anything that’s designed to be used by plugins?

The only scanning we do is to find test classes. We implement that by scanning the bytecode using ASM, rather than via ClassLoaders. This code is currently internal code, and is not available to plugins.

In general, it’s not a good idea to scan by loading classes (it’s slow, it triggers static initialisers, it requires the classes to be loadable, it makes assumptions about the classloader hierarchy etc). I would think that an annotation processor would be a good fit for what you’re trying to do.

Hi Adam,

Thanks for getting back to me, how would I configure an annotation processor to run on a JAR or WAR package within a gradle plugin. I understand how annotation processors work but I don’t want it to scan the contents of my plugin JAR instead I want it to scan the contents of the JAR or WAR being created by the build script?