Quarkus项目编译报错:rawModel为null导致无法调用Model.getParent()的问题求助
Quarkus项目编译报错:rawModel为null导致无法调用Model.getParent()的问题求助
问题描述
我尝试创建一个Quarkus项目,但遇到了编译错误,具体操作步骤如下:
- 打开Quarkus项目生成平台,选择版本2.16.4.Final,构建工具选Maven,Java版本17,添加RestEasy Reactive扩展后生成项目
- 用IntelliJ IDEA打开项目,本地Maven版本为3.6.3
- 执行编译/Dev模式时,出现以下错误:
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.16.4.Final:dev (default-cli) on project code-with-quarkus: Quarkus code generation phase has failed: Failed to initialize Quarkus bootstrap Maven artifact resolver: Failed to load current project at C:\Users\x.y\Desktop\aaaaa\pom.xml: Cannot invoke "org.apache.maven.model.Model.getParent()" because "rawModel" is null -> [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
我的pom.xml内容如下:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>org.acme</groupId> <artifactId>code-with-quarkus</artifactId> <version>1.0.0-SNAPSHOT</version> <properties> <compiler-plugin.version>3.10.1</compiler-plugin.version> <maven.compiler.release>11</maven.compiler.release> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> <quarkus.platform.version>2.16.4.Final</quarkus.platform.version> <skipITs>true</skipITs> <surefire-plugin.version>3.0.0-M7</surefire-plugin.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-resteasy-reactive</artifactId> </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-arc</artifactId> </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>${quarkus.platform.group-id}</groupId> <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus.platform.version}</version> <extensions>true</extensions> <executions> <execution> <goals> <goal>build</goal> <goal>generate-code</goal> <goal>generate-code-tests</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>${compiler-plugin.version}</version> <configuration> <compilerArgs> <arg>-parameters</arg> </compilerArgs> </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire-plugin.version}</version> <configuration> <systemPropertyVariables> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <maven.home>${maven.home}</maven.home> </systemPropertyVariables> </configuration> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>${surefire-plugin.version}</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <systemPropertyVariables> <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <maven.home>${maven.home}</maven.home> </systemPropertyVariables> </configuration> </execution> </executions> </plugin> </plugins> </build> <profiles> <profile> <id>native</id> <activation> <property> <name>native</name> </property> </activation> <properties> <skipITs>false</skipITs> <quarkus.package.type>native</quarkus.package.type> </properties> </profile> </profiles> </project>
现在想请教大家,该如何解决这个错误,成功创建并运行Quarkus应用?
可能的解决方案
1. 升级Maven版本到兼容范围
Quarkus 2.16.x版本对Maven的最低要求是3.8.1,你当前用的3.6.3版本过低,很可能是导致这个兼容性报错的核心原因。建议你升级Maven到3.8.1或更高版本(比如最新的3.9.x系列),步骤如下:
- 下载对应版本的Maven
- 配置系统环境变量
MAVEN_HOME指向新的Maven目录 - 更新
PATH变量,将新Maven的bin目录加入 - 打开新终端,执行
mvn -v确认版本已更新
2. 修正pom.xml的Java版本配置
你生成项目时选的是Java17,但pom.xml里的maven.compiler.release配置的是11,这会导致编译环境不一致。把这个属性改成17:
<maven.compiler.release>17</maven.compiler.release>
修改后执行mvn clean install重新编译试试。
3. 重新导入项目清除IDE缓存
有时候IDE导入项目时会出现缓存异常,你可以试试:
- 关闭IntelliJ,删除项目根目录下的
.idea文件夹和target目录 - 重新打开IntelliJ,选择
File -> Open重新导入项目 - 等IDE完成Maven依赖下载和索引后,再尝试运行
mvn quarkus:dev
4. 直接用命令行操作排除IDE影响
如果IDE里的问题还存在,可以脱离IDE,在项目根目录打开终端执行以下命令:
mvn clean install mvn quarkus:dev
看看能不能正常运行,排除IDE配置的干扰。
备注:内容来源于stack exchange,提问作者enesk
相关产品推荐
相关产品推荐

