英文:
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
<?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>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-cdi</artifactId>
<version>${mybatis.cdi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!-- to fix bug with reactive -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-context-propagation</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongo.version}</version>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<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.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>
11
</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.0.7</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论