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

如何在多模块Maven项目的指定pom.xml中添加<finalName>标签

如何让OpenRewrite配方仅作用于多模块Maven项目的指定pom.xml文件

你可以通过两种方式限制OpenRewrite配方仅作用于目标模块的pom.xml:

方法一:通过文件路径精准匹配

在配方中添加fileMatcher参数,指定仅对batch/pom.xml文件执行操作。修改后的配方如下:

- org.openrewrite.xml.AddOrUpdateChildTag:
    parentXPath: /project//build
    newChildTag: <finalName>batch</finalName>
    fileMatcher: "batch/pom.xml"

如果你的batch模块嵌套在更深的目录中,可以使用glob通配符匹配,比如**/batch/pom.xml会匹配所有子目录下的batch模块pom文件。

方法二:基于Maven模块标识过滤

如果不想硬编码文件路径,可通过模块的artifactId(配合可选的groupId)精准定位目标模块,使用org.openrewrite.maven.MavenIsoRecipe包裹原有配方:

- org.openrewrite.maven.MavenIsoRecipe:
    recipe:
      - org.openrewrite.xml.AddOrUpdateChildTag:
          parentXPath: /project//build
          newChildTag: <finalName>batch</finalName>
    artifactId: batch
    # 可选:如果需要更精准匹配,可添加groupId
    # groupId: com.yourcompany

这种方式会自动识别所有artifactId为batch的Maven模块,仅对其pom.xml执行添加<finalName>标签的操作,适合模块结构可能调整的场景。

应用上述任意一种配方后,只有batch/pom.xml会被添加<finalName>标签,父模块和web模块的pom.xml不会受到影响,符合你的期望结果。

内容的提问来源于stack exchange,提问作者Rodrigo Carvalho Silva

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 20:09:52