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

非Maven/Gradle构建(Ant)下运行OpenRewrite Recipes的方法咨询

在Ant构建项目中运行OpenRewrite Recipes的方法

支持在Ant构建的项目中运行OpenRewrite Recipes,无需依赖专属构建工具插件,可通过直接调用OpenRewrite的Java API或Ant的java任务实现,具体步骤如下:

  • 准备OpenRewrite依赖包
    从Maven中央仓库下载OpenRewrite核心库及对应Recipe依赖(如rewrite-core、rewrite-java等,依需求选择),将JAR包放置到项目的依赖目录(如lib/)。

  • 编写Ant任务配置
    在build.xml中添加java任务,指定OpenRewrite的主类,配置类路径、源代码目录、输出目录及目标Recipe:

    <target name="run-rewrite">
      <java classname="org.openrewrite.java.Main" fork="true">
        <classpath>
          <fileset dir="lib" includes="*.jar"/>
        </classpath>
        <arg value="--recipe"/>
        <arg value="org.openrewrite.java.cleanup.RemoveUnusedImports"/>
        <arg value="--source-directory"/>
        <arg value="src/main/java"/>
        <arg value="--output-directory"/>
        <arg value="target/rewritten-java"/>
      </java>
    </target>
    

    参数说明:

    • --recipe:指定要执行的Recipe全类名,多个Recipe用逗号分隔
    • --source-directory:项目源代码目录
    • --output-directory:处理后代码的输出目录,建议不直接覆盖原代码
  • 执行Rewrite任务
    在命令行运行ant run-rewrite即可触发Recipe执行。

若需自定义Recipe或复杂配置,可通过--config-file参数指定YAML配置文件,在文件中定义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.07.06 03:27:34