使用OpenRewrite Spring Boot3升级配方时父POM未更新的问题
OpenRewrite升级Spring Boot 3时pom.xml未更新及YAML解析问题解决
pom.xml未更新的排查方向
- 确认OpenRewrite插件配置中是否正确启用
org.openrewrite.java.spring.boot3.UpgradeSpringBoot3_0配方,且插件绑定到了合适的构建阶段(如process-sources) - 检查pom.xml里的Spring Boot版本声明格式:配方仅识别
<parent>节点下的spring-boot-starter-parent,或是<properties>中的spring-boot.version属性,若版本声明不在这些位置,配方不会自动修改 - 执行构建时添加
--verbose参数,查看详细日志,确认是否存在跳过pom.xml修改的触发条件
YAML解析错误的修复方法
报错line 1:0 missing '@' at 'org'是因为OpenRewrite误将YAML资源文件当作Java类解析,解决步骤:
- 调整OpenRewrite插件的
<sources>配置,仅包含Java源码目录(src/main/java、src/test/java),排除资源目录(src/main/resources、src/test/resources) - 若需要升级YAML配置中的Spring Boot 3适配项,需单独引入对应的YAML升级配方(如
org.openrewrite.java.spring.boot3.SpringBoot30YamlConfiguration)
示例正确配置
<plugin> <groupId>org.openrewrite.maven</groupId> <artifactId>rewrite-maven-plugin</artifactId> <version>5.40.0</version> <configuration> <activeRecipes> <recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot3_0</recipe> <!-- 若需处理YAML配置,添加以下配方 --> <recipe>org.openrewrite.java.spring.boot3.SpringBoot30YamlConfiguration</recipe> </activeRecipes> <sources> <source>src/main/java</source> <source>src/test/java</source> </sources> </configuration> <dependencies> <dependency> <groupId>org.openrewrite.recipe</groupId> <artifactId>rewrite-spring</artifactId> <version>5.40.0</version> </dependency> </dependencies> </plugin>
内容的提问来源于stack exchange,提问作者SDev
相关产品推荐
相关产品推荐

