如何仅向特定.properties文件添加属性?
解决OpenRewrite仅向特定.properties文件添加属性的问题
你遇到的问题源于fileMatcher配置中的引号转义错误,导致路径匹配失效。以下是两种可靠的解决方案:
方案一:修正ChangePropertyValue配置
移除fileMatcher的转义引号,YAML中直接使用通配符路径即可:
recipeList: - org.openrewrite.properties.ChangePropertyValue: propertyKey: netty.version newValue: 4.1.132.Final addIfMissing: true fileMatcher: **/gradle.properties
若路径包含特殊字符,可改用单引号包裹(无需转义):
fileMatcher: '**/gradle.properties'
方案二:使用AddProperty recipe(更贴合需求)
由于你的核心需求是仅在属性缺失时添加,AddProperty是专门为此场景设计的recipe,配置更直观:
recipeList: - org.openrewrite.properties.AddProperty: propertyKey: netty.version propertyValue: 4.1.132.Final fileMatcher: **/gradle.properties
额外说明
- 通配符路径支持更精确的匹配,比如针对特定目录下的文件可写为
src/main/resources/**/custom.properties - 若仍存在匹配问题,可检查路径是否与项目中实际文件结构完全匹配
内容的提问来源于stack exchange,提问作者PapaBear
相关产品推荐
相关产品推荐

