Replacing ClassGraph with Jandex
In this year’s Code Camp, I worked on using Jandex in our code.
The goal was to replace our existing classpath scanning approach with Jandex, and then make validation behave correctly in this new world.
If you’ve never heard of Jandex before, it is essentially a lightweight index of Java classes and annotations. Instead of scanning everything at runtime, we can rely on a precomputed index. And we don't need to rely on Classloading as much.
Why change Anything?
Our previous approach used ClassGraph for indexing Java classes. It worked, but it also meant we depended on runtime scanning behavior.
The idea behind the Code Camp project was
- use Jandex instead of ClassGraph for indexing
- pass the indexing choice through the configuration
- adapt project validation so it only runs when the Jandex index is actually available
Using Jandex
The first step was to replace ClassGraph with Jandex for indexing Java classes. This gives us a more lightweight way to collect the metadata we need, without relying on broad runtime scanning. This part is already done and fully merged.
Fully Adaping Config
After that, I made sure the Jandex setup is available throughout the configuration stack. This way, we do not have to load the actual Java classes until they are really needed. That should give us a small performance boost and keeps the indexing setup cleaner across the platform. This part is still in progress.
Validate once Jandex is available
The last step was to update our workspace validation approach. Instead of validating too early, we now wait until the Jandex index has been built and is ready. This ensures that validation only runs on complete and reliable data, which makes the overall workflow more robust.