You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不修改构建时,能否在rewrite.yml中定义多个recipes并执行?

在rewrite.yml中定义多个Recipes并单条命令执行的方法

完全可以在rewrite.yml中定义多个recipes,通过单条命令触发它们按顺序执行,具体配置和操作方式如下:

配置方式

在rewrite.yml中创建一个组合式recipe,通过recipeList字段按执行顺序列出需要运行的所有recipe,示例配置如下:

type: specs.openrewrite.org/v1beta/recipe
name: com.example.MyCombinedRecipe
displayName: 自定义组合执行Recipe
description: 按顺序运行多个清理、格式化类Recipe
recipeList:
  - org.openrewrite.java.cleanup.RemoveUnusedImports
  - org.openrewrite.java.format.AutoFormat
  - com.example.MyCustomRecipe # 替换为你的自定义Recipe ID

执行命令

配置完成后,直接执行常规的rewrite运行命令即可,所有recipeList中的recipe会从上到下依次执行:

  • Maven环境:mvn rewrite:run
  • Gradle环境:./gradlew rewriteRun

注意事项

  • 确保每个recipe的ID准确无误,内置recipe可通过官方文档确认ID信息
  • 自定义recipe需提前在rewrite.yml中完成定义,或确保其所在依赖已被正确引入
  • 执行顺序严格遵循recipeList中的排列顺序,前一个recipe执行完成后才会启动下一个

内容的提问来源于stack exchange,提问作者P Barry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:00:55