如何在多模块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
相关产品推荐
相关产品推荐

