即使使用 jandex 插件和空 META-INF/beans.xml,Quarkus 也无法找到 Jandex 索引的第三方类

Quarkus cant find third party clasess for Jandex index even with jandex plugin and an empty META-INF/beans.xml

来自智利的维克多。

我有一个 quarkus 应用程序,我想对 Oracle 数据库使用 quarkus-hibernate-orm,但是我的实体 类 在第三方 jar 中,所以我只是将依赖项放在 pom 中(的实体 类) 以下是 quarkus-hibernate-orm 依赖项,当然还有其他 quarkus 依赖项。

我试过这个:

jandex 插件和 beans.xml 解决方案对我不起作用(我没有尝试第三个选项,但似乎对其他人已经尝试过的前两个选项有效。)

使用 quarkus 0.20.0 和 0.19.1 进行测试并显示相同的错误。

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cl.myproj</groupId>
    <artifactId>reposirorio-myproj</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <quarkus.version>0.19.1</quarkus.version>
        <surefire-plugin.version>2.22.1</surefire-plugin.version>
        <compiler-plugin.version>3.8.0</compiler-plugin.version>
        <docker-plugin.version>0.28.0</docker-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-bom</artifactId>
                <scope>import</scope>
                <type>pom</type>
                <version>${quarkus.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-hibernate-orm</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-agroal</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-jsonb</artifactId>
        </dependency>


        <!-- Testing: -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.jandex</groupId>
            <artifactId>jandex-maven-plugin</artifactId>
            <version>1.0.6</version>
        </dependency>


        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0.2.0</version>
        </dependency>
        <dependency>
            <groupId>cl.entities</groupId>
            <artifactId>libMyEntities</artifactId>
            <version>1.0.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <!-- the parameters=true option is critical so that RESTEasy works fine -->
                    <parameters>true</parameters>
                </configuration>
            </plugin>
            <plugin>
                <!-- you need this specific version to integrate with the other build helpers -->
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemProperties>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <!-- This is what injects the magic Quarkus bytecode -->
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <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>

    <profiles>
        <profile>
            <!-- Optionally activate this profile to compile the demo into native! -->
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.quarkus</groupId>
                        <artifactId>quarkus-maven-plugin</artifactId>
                        <version>${quarkus.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemProperties>
                                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                                    </systemProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>eclipse</id>
            <activation>
                <property>
                    <!-- This is a trick to have the profile automatically activated by Eclipse -->
                    <name>m2e.version</name>
                </property>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                        <plugin>
                            <groupId>org.eclipse.m2e</groupId>
                            <artifactId>lifecycle-mapping</artifactId>
                            <version>1.0.0</version>
                            <configuration>
                                <lifecycleMappingMetadata>
                                    <pluginExecutions>
                                        <pluginExecution>
                                            <pluginExecutionFilter>
                                                <groupId>io.fabric8</groupId>
                                                <artifactId>
                                                    docker-maven-plugin
                                                </artifactId>
                                                <versionRange>
                                                    [0.28.0,)
                                                </versionRange>
                                                <goals>
                                                    <goal>start</goal>
                                                    <goal>stop</goal>
                                                </goals>
                                            </pluginExecutionFilter>
                                            <action>
                                                <ignore></ignore>
                                            </action>
                                        </pluginExecution>
                                    </pluginExecutions>
                                </lifecycleMappingMetadata>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>

make mvn clean install -DskipTests(对于跳过测试)控制台输出是这样的:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.440 s
[INFO] Finished at: 2019-08-02T12:53:29-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:0.19.1:build (default) on project reposirorio-compromiso: Failed to build a runnable JAR: Failed to build a runner jar: Failed to augment application classes: Build failure: Build failed due to errors
[ERROR]     [error]: Build step io.quarkus.hibernate.orm.deployment.HibernateOrmProcessor#build threw an exception: io.quarkus.deployment.configuration.ConfigurationError: Unable to properly register the hierarchy of the following JPA classes as they are not in the Jandex index:
[ERROR]     - org.springframework.data.domain.Auditable
[ERROR]     - org.springframework.data.domain.Persistable
[ERROR] Consider adding them to the index either by creating a Jandex index for your dependency via the Maven plugin, an empty META-INF/beans.xml or quarkus.index-dependency properties.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我认为构建成功。

非常感谢。

嗯,我不太确定 Spring 数据是否适用于 Quarkus。我们有自己的图层,称为 Panache。

要解决您遇到的错误,您需要为包含上述两个 类 的 Spring 数据工件创建索引。

您可以使用我在此处的回答中描述的 quarkus.index-dependency 方法来做到这一点:.

在知道问题不完全正确的情况下创建此回复。

据我了解,这不是 hibernate-orm 错误或 "like jpa problem"。在这种情况下,错误始终是:"Cant find spring classes":

[ERROR]     - org.springframework.data.domain.Auditable
[ERROR]     - org.springframework.data.domain.Persistable

而不是 "Cant up the hibernate libraries, etc..." 所以我的问题的正确答案是,使用此页面的方法:How to create a Jandex index in Quarkus for 类 in a external module。 (就像我们的合作伙伴 Guillaume 所说的!)但是,要将 Spring 类 放入索引中。 (Spring 是我项目的实体依赖项的依赖项。)

刚刚像这样配置了我的 application.properties:

quarkus.index-dependency.springd.group-id=org.springframework.data quarkus.index-dependency.springd.artifact-id=spring-data-commons

结果是:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.878 s
[INFO] Finished at: 2019-08-02T16:02:14-04:00
[INFO] ------------------------------------------------------------------------

因为我刚刚在 mvn repo 搜索中的那个 jar (org.springframework.data) 中找到了这个 类,所以按预期工作。

非常感谢。