quarkus

Quarkus - get an access to Jandex index


I'm new to the subject of Quarkus. How can I use Jandex index in a java class? I added a goal to the maven to build index, then I created a class but don't know go how to use it? I can create a index by using Indexer but then I need to decalare all classes to scan. How can I solve it better?

private void testIndex() {
        Indexer indexer = new Indexer();
        try
        {
            indexer.indexClass( MyClass.class );
            Collection< ClassInfo > knownClasses = indexer.complete()
                .getKnownClasses();
        }
        catch( IOException e )
        {
            throw new RuntimeException( e );
        }
    }

Solution

  • The Jandex index is generated at build time, so your best bet is to write a Quarkus extension, which can participate in the build process. In your extension's processor, you can declare Build Step methods with arguments. Quarkus will automatically invoke your build steps with the arguments of the type you request.

    So, to get a Jandex, index, you could write a method in your extension processor something like this:

       @BuildStep
        void doAThingWithTheIndex(ApplicationIndexBuildItem applicationIndex,
                CombinedIndexBuildItem combinedIndex) {
            ...
        }
    

    See also: