简体   繁体   中英

Quarkus + Panache + RestEasy Native Image build fails

I have the following simplified setup:

1)

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/api")
public class MyResource {

    public MyResource() {
    }

    @GET
    @Path("/myPath/")
    public void get() {
    }
}

2)

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import javax.persistence.Entity;

@Entity
public class MyEntity extends PanacheEntity {

    public String hello;

    public MyEntity() {
        //For Panache only
    }
}

3) pom.xml:

[...]
    <properties>
            <compiler-plugin.version>3.8.1</compiler-plugin.version>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
            <quarkus-plugin.version>1.5.0.Final</quarkus-plugin.version>
            <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
            <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
            <quarkus.platform.version>1.5.0.Final</quarkus.platform.version>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>${quarkus.platform.group-id}</groupId>
                    <artifactId>${quarkus.platform.artifact-id}</artifactId>
                    <version>${quarkus.platform.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-hibernate-orm-panache</artifactId>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-jdbc-mariadb</artifactId>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-resteasy</artifactId>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>io.quarkus</groupId>
                    <artifactId>quarkus-maven-plugin</artifactId>
                    <version>${quarkus-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <profiles>
            <profile>
                <id>native</id>
                <activation>
                    <property>
                        <name>native</name>
                    </property>
                </activation>
                <build/>
                <properties>
                    <quarkus.package.type>native</quarkus.package.type>
                </properties>
            </profile>
        </profiles>
    </project>

4) application.properties

quarkus.datasource.db-kind = mariadb
quarkus.datasource.username = admin
quarkus.datasource.password = admin
quarkus.datasource.jdbc.url = jdbc:mariadb://localhost:5432/mydatabase
quarkus.hibernate-orm.database.generation = drop-and-create

When I run this with the native maven profile (mvn clean package -Pnative) I get:

Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing com.oracle.svm.reflect.Class_getNestHost_d0409f1154f6242e625526eadd05fbcd60e7d7e9.invoke(java.lang.Object, java.lang.Object[]) 
Parsing context:
        parsing java.lang.reflect.Method.invoke(Method.java:566)
        parsing javax.enterprise.util.AnnotationLiteral.invoke(AnnotationLiteral.java:288)
        parsing javax.enterprise.util.AnnotationLiteral.getMemberValue(AnnotationLiteral.java:276)
        parsing javax.enterprise.util.AnnotationLiteral.hashCode(AnnotationLiteral.java:246)
        parsing org.graalvm.collections.EconomicMapImpl.getHashIndex(EconomicMapImpl.java:414)
[...]
Caused by: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.getNestHost() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
[...]
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. 

Running it with --report-unsupported-elements-at-runtime didn't help too much either. When I delete the MyEntity class, it successfully compiles as a native executable on my Mac + Graalvm-ce-java11-20.0.0

Any idea what's wrong here?

I update to 20.0.0 and everything works perfectly. I just found only one way to hit that error and that is if you omit to set properly GraalVM. The environment variables in my mac are:

export GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.0.0/Contents/Home
export JAVA_HOME=${GRAALVM_HOME}
export PATH=${GRAALVM_HOME}/bin:$PATH

Let me know if that works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM