Gradle processResources-文件包含$ ;性格
如何在包含Gradle processResources-文件包含$ ;性格,gradle,spring-boot,Gradle,Spring Boot,如何在包含$字符的文件上执行gradle processResources,而不转义文件中的$ 我在/resources/static文件夹中找到了一些静态html文件,正如。但是,当我尝试执行gradleprocessresources时,gradle抛出一个异常 Caused by: org.gradle.api.GradleException: Could not copy file '[...]/src/main/resources/static/dollar.html' to '
$
字符的文件上执行gradle processResources
,而不转义文件中的$
我在
/resources/static
文件夹中找到了一些静态html文件,正如。但是,当我尝试执行gradleprocessresources
时,gradle抛出一个异常
Caused by: org.gradle.api.GradleException:
Could not copy file '[...]/src/main/resources/static/dollar.html'
to '[...]/build/resources/main/static/dollar.html'.
[...]
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:
SimpleTemplateScript7.groovy: 1: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5"
or bracket the value expression "${5}" @ line 1, column 10.
out.print("""<!DOCTYPE html>
configure(tasks.processResources) {
filesMatching('static/dollar.html') {
filter = ???
}
}
导致问题的
dollar.html
文件可以简化为:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div>Dollar $</div>
</body>
美元$
提供了宝贵的见解。这个问题确实是由于使用了expand()
(虽然由于它位于父项目中的allProjects()
脚本中,所以不能立即看到)。首先添加expand()
的原因是希望填充application.properties
文件中的属性(以便通过Spring Boot提供这些属性)
解决方案:使用
filesMatching()
仅expand()
选定文件。以下代码片段解决了与Spring Boot相关的特定问题:
processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}
processResources通常只复制资源,不做任何其他操作。您可能正在使用expand()将${someProp}占位符替换为值。向我们显示您的生成文件。@jbnize如果您的假设是正确的,请参阅下面的“我的”。谢谢如果属性键包含点字符。例如
a.b.c.d=yes
如何绑定?我遇到了异常groovy.lang.MissingPropertyException:没有这样的属性
我的应用程序.yml
位于:root:subprojectA
类路径中。fileMatching
读取什么路径?另外,如果YAML配置具有多个配置文件,我应该写什么?
processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}