Templates 渐变复制任务展开yaml文件转义整个字符串
我有以下gradle任务:Templates 渐变复制任务展开yaml文件转义整个字符串,templates,gradle,yaml,Templates,Gradle,Yaml,我有以下gradle任务: processResources { inputs.properties(project.properties.findAll { it.value instanceof String }) filesMatching("**/*.yaml") { filteringCharset = 'UTF-8' expand project.properties } } 我用来处理包含变量占位符的spring boot
processResources {
inputs.properties(project.properties.findAll { it.value instanceof String })
filesMatching("**/*.yaml") {
filteringCharset = 'UTF-8'
expand project.properties
}
}
我用来处理包含变量占位符的spring boot application.yaml文件
如何在不转义每个特殊字符的情况下转义整个日志模式,从而保持模式干净
application.yaml:
logging:
pattern:
console: %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
尝试使用slashy字符串,但未成功:
1.审判:
/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/
错误:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript8.groovy: 138: expecting '}', found 'HH' @ line 138, column 60.
ATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.S
^
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript10.groovy: 138: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 138, column 15.
console: $/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/$
^
2.审判:
$/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/$
错误:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript8.groovy: 138: expecting '}', found 'HH' @ line 138, column 60.
ATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.S
^
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript10.groovy: 138: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 138, column 15.
console: $/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/$
^
考虑到YAML文件包含的字符被
expand
方法解释为标记,依赖于Groovy的SimpleTemplateEngine
,您应该使用类似filter
方法的替代方法
显示了一些
过滤器的示例。通过使用底层AntReplaceTokens
您可能会有更好的运气,因为它使用@token@
作为表示法。鉴于YAML文件包含的字符被expand
方法解释为令牌,依赖Groovy的SimpleTemplateEngine
,您应该使用另一种方法,如过滤器
方法
显示了一些过滤器的示例。通过使用底层AntReplaceTokens
您可能会有更好的运气,因为它使用@token@
作为表示法