How to create a Jandex index in Quarkus for classes in a external module

岁酱吖の 提交于 2019-11-27 23:08:59

Quarkus automatically indexes the main module but, when you have additional modules containing CDI beans, entities, objects serialized as JSON, you need to explicitly index them.

There are a couple of different (easy to implement) options to do so.

Using the Jandex Maven plugin

Just add the following to your pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.jboss.jandex</groupId>
      <artifactId>jandex-maven-plugin</artifactId>
      <version>1.0.6</version>
      <executions>
        <execution>
          <id>make-index</id>
          <goals>
            <goal>jandex</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

It's the most beneficial option if your dependency is external to your project and you want to build the index once and for all.

Adding an empty META-INF/beans.xml

If you add an empty META-INF/beans.xml file in your src/main/resources, the classes will also be indexed.

The classes will be indexed by Quarkus itself.

Indexing other dependencies

If you can't modify the dependency (think of a third-party dependency, for instance), you can still index it by adding an entry to your application.properties:

quarkus.index-dependency.<name>.group-id=
quarkus.index-dependency.<name>.artifact-id=
quarkus.index-dependency.<name>.classifier=(this one is optional)

with <name> being a name you choose to identify your dependency.

I've tried to add Jandex index, to add beans.xml and also to Indexing other dependencies as described in @emre-işık answer, however my third party class (EpAutomationRs) wasn't registered for reflection in native mode. So I've ended up with quick and dirty solution for registering it (see below). I've created an unused REST JSON endpoint which returns the class.

/**
 * the purpose of this method is to register for reflection EpAutomationRs class
 *
 * @return
 */
@GET
@Path(GET_EMPTY_RS)
@Produces(MediaType.APPLICATION_JSON)
public EpAutomationRs entry() {
    return new EpAutomationRs();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!