Quarkus本地镜像构建失败

huangapple go评论88阅读模式
英文:

Quarkus native image build fails

问题

当我正在构建本地镜像时,我遇到了反射问题。

> com.oracle.svm.hosted.substitute.DeletedElementException: 不支持的字段 java.lang.Class.newInstanceCallerCache 可达:声明此元素的类已被替换,但此元素在替换类中不存在。

如何修复?我的环境是 GraalVM 20 和 Zulu OpenJDK 11

我的 pom 文件:

    <?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>org.example</groupId>
        <artifactId>qd</artifactId>
        <version>0.0.1</version>
    
        <properties>
            <quarkus.version>1.3.0.Final</quarkus.version>
            <surefire.version>2.22.2</surefire.version>
            <mybatis.version>3.5.4</mybatis.version>
            <mybatis.cdi.version>1.1.1</mybatis.cdi.version>
            <kafka.version>2.4.1</kafka.version>
            <resteasy.version>4.5.3.Final</resteasy.version>
            <mongo.version>3.12.2</mongo.version>
            <testcontainer.version>1.13.0</testcontainer.version>
        </properties>
    
        <!-- 依赖管理 -->
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>io.quarkus</groupId>
                    <artifactId>quarkus-bom</artifactId>
                    <version>${quarkus.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <!-- 依赖 -->
        <dependencies>
            <!-- 各种依赖 -->
        </dependencies>
    
        <!-- 构建配置 -->
        <build>
            <plugins>
                <!-- Quarkus 插件 -->
                <plugin>
                    <groupId>io.quarkus</groupId>
                    <artifactId>quarkus-maven-plugin</artifactId>
                    <version>${quarkus.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!-- 其他插件 -->
            </plugins>
        </build>
    
        <!-- 配置 profile -->
        <profiles>
            <profile>
                <id>native</id>
                <properties>
                    <quarkus.package.type>native</quarkus.package.type>
                </properties>
            </profile>
        </profiles>
    </project>

注意:由于您要求只返回翻译后的内容,因此我只提供了代码部分的翻译,而省略了问题的答复部分。如果您还有其他问题,请随时提问。

英文:

When I am building a native image build I am facing an issue with reflection

> com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported field java.lang.Class.newInstanceCallerCache is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class

How can I fix it? My environment GraalVM 20 and Zulu OpenJdk11

My pom

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;org.example&lt;/groupId&gt;
&lt;artifactId&gt;qd&lt;/artifactId&gt;
&lt;version&gt;0.0.1&lt;/version&gt;
&lt;properties&gt;
&lt;quarkus.version&gt;1.3.0.Final&lt;/quarkus.version&gt;
&lt;surefire.version&gt;2.22.2&lt;/surefire.version&gt;
&lt;mybatis.version&gt;3.5.4&lt;/mybatis.version&gt;
&lt;mybatis.cdi.version&gt;1.1.1&lt;/mybatis.cdi.version&gt;
&lt;kafka.version&gt;2.4.1&lt;/kafka.version&gt;
&lt;resteasy.version&gt;4.5.3.Final&lt;/resteasy.version&gt;
&lt;mongo.version&gt;3.12.2&lt;/mongo.version&gt;
&lt;testcontainer.version&gt;1.13.0&lt;/testcontainer.version&gt;
&lt;/properties&gt;
&lt;dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-bom&lt;/artifactId&gt;
&lt;version&gt;${quarkus.version}&lt;/version&gt;
&lt;type&gt;pom&lt;/type&gt;
&lt;scope&gt;import&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/dependencyManagement&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-resteasy&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-arc&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-resteasy-jackson&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-flyway&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-agroal&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-config-yaml&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-smallrye-health&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-jdbc-postgresql&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-smallrye-reactive-messaging-kafka&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-smallrye-openapi&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-resteasy-jsonb&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-resteasy-mutiny&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-mongodb-client&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-smallrye-jwt&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mybatis&lt;/groupId&gt;
&lt;artifactId&gt;mybatis&lt;/artifactId&gt;
&lt;version&gt;${mybatis.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mybatis&lt;/groupId&gt;
&lt;artifactId&gt;mybatis-cdi&lt;/artifactId&gt;
&lt;version&gt;${mybatis.cdi.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.kafka&lt;/groupId&gt;
&lt;artifactId&gt;kafka-clients&lt;/artifactId&gt;
&lt;version&gt;${kafka.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt --&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.jsonwebtoken&lt;/groupId&gt;
&lt;artifactId&gt;jjwt&lt;/artifactId&gt;
&lt;version&gt;0.9.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- to fix bug with reactive --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
&lt;artifactId&gt;resteasy-context-propagation&lt;/artifactId&gt;
&lt;version&gt;${resteasy.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mongodb&lt;/groupId&gt;
&lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
&lt;version&gt;${mongo.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-junit5&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
&lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;io.quarkus&lt;/groupId&gt;
&lt;artifactId&gt;quarkus-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${quarkus.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;build&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.0&lt;/version&gt;
&lt;configuration&gt;
&lt;release&gt;
11
&lt;/release&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;version&gt;${surefire.version}&lt;/version&gt;
&lt;configuration&gt;
&lt;systemProperties&gt;
&lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager&lt;/java.util.logging.manager&gt;
&lt;/systemProperties&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jboss.jandex&lt;/groupId&gt;
&lt;artifactId&gt;jandex-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;1.0.7&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;make-index&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;jandex&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;profiles&gt;
&lt;profile&gt;
&lt;id&gt;native&lt;/id&gt;
&lt;properties&gt;
&lt;quarkus.package.type&gt;native&lt;/quarkus.package.type&gt;
&lt;/properties&gt;
&lt;/profile&gt;
&lt;/profiles&gt;
&lt;/project&gt;

答案1

得分: 1

根据评论中的说明,移除非 Quarkus 的依赖项可能会有所帮助。

你的依赖项中也有一些可以替换为 Quarkus 等效库的库,例如 kafka-client。尝试用 Quarkus 等效库来替换它们。

以下是该库的链接:
https://mvnrepository.com/artifact/io.quarkus/quarkus-kafka-client

很难确定是哪个依赖项导致了问题,但我建议尝试替换可能的依赖项,如果问题仍然存在,你可以尝试移除剩余的依赖项。

英文:

As stated in the comments, removing non-quarkus dependencies can help.

There are also libraries in your dependencies which have a quarkus equivalent, for example kafka-client. Try substituting those with the quarkus equivalent.

Here a link to said library:
https://mvnrepository.com/artifact/io.quarkus/quarkus-kafka-client

It's hard to tell which dependency causes the problem excatly, but I would suggest to substitute the ones that are possible, and if the problem persists you can try removing the remaining dependencies.

huangapple
  • 本文由 发表于 2020年4月3日 22:18:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/61013910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定