如何在 Quarkus 中为外部模块中的类创建 Jandex 索引 [英] How to create a Jandex index in Quarkus for classes in a external module

查看:35
本文介绍了如何在 Quarkus 中为外部模块中的类创建 Jandex 索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我有一个多模块的 maven 层次结构:

First of all, I have a multi-module maven hierarchy like that:

├── project (parent pom.xml)
│   ├── service
│   ├── api-library

现在问题来了:

我正在服务模块中编写一个 JAX-RS 端点,它使用 api-library 中的类.
当我启动 quarkus 时,我收到此警告:

I am writing a JAX-RS Endpoint in the service module which uses classes in the api-library.
When I start quarkus, I am getting this warning:

13:01:18,784 WARN  [io.qua.dep.ste.ReflectiveHierarchyStep] Unable to properly register the hierarchy of the following classes for reflection as they are not in the Jandex index:
- com.example.Fruit
- com.example.Car
Consider adding them to the index either by creating a Jandex index for your dependency or via quarkus.index-dependency properties.

这两个类com.example.Fruitcom.example.Car 位于api-library 模块中.

This two classes com.example.Fruit and com.example.Car are located in the api-library module.

所以我想我需要将它们添加到 application.properties 中的 Jandex 索引依赖项中.

So I think I need to add them to the Jandex index-dependency in the application.properties.

但是如何将 Jandex 索引依赖项添加到 quarkus 中?

推荐答案

Quarkus 自动索引主模块,但是,当您有包含 CDI bean、实体、序列化为 JSON 的对象的附加模块时,您需要显式索引它们.

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.

使用 Jandex Maven 插件

只需将以下内容添加到附加模块 pom.xml 中:

Just add the following to the additional module pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.jboss.jandex</groupId>
      <artifactId>jandex-maven-plugin</artifactId>
      <version>1.1.0</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.

使用 Gradle Jandex 插件

如果你使用 Gradle,有一个第三方插件可以生成 Jandex 索引:https://github.com/kordamp/jandex-gradle-plugin .

If you are using Gradle, there is a third party plugin allowing to generate a Jandex index: https://github.com/kordamp/jandex-gradle-plugin .

添加一个空的 META-INF/beans.xml

如果您在附加模块 src/main/resources 中添加一个空的 META-INF/beans.xml 文件,类也将被索引.

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

这些类将由 Quarkus 本身索引.

The classes will be indexed by Quarkus itself.

索引其他依赖项

如果您无法修改依赖项(例如,考虑第三方依赖项),您仍然可以通过在 application.properties 中添加一个条目来索引它:

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.

这篇关于如何在 Quarkus 中为外部模块中的类创建 Jandex 索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆