大佬教程收集整理的这篇文章主要介绍了Gradle processResources-文件包含$字符,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
JB Nizet的评论提供了宝贵的见解。问题的确是由于使用的expand()
(尽管由于位于allProjects()
父项目的脚本中,所以无法立即看到)。首先expand()
添加该文件的原因是希望填充文件中的info.build。*属性application.propertIEs
(以便可以通过Spring
Boot的info端点使用这些属性)。
解决方案:filesmatching()
仅用于expand()
选定的文件。以下代码片段解决了与Spring Boot相关的特定问题:
processresources {
filesmatching('application.propertIEs') {
expand(project.propertIEs)
}
}
如何gradle processresources
在包含$
字符的文件上执行而不转义$
文件中的?
我有一些静态html文件位于Spring Boot参考文档/resources/static
建议的文件夹中。但是,当我尝试执行时,Gradle会引发异常gradle
processresources
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>
据我了解,出现此问题是因为其中一个$
静态文件中$
有一个字符,并且在处理资源时是表达式的保留字符。
建议的解决方案:
$
with \$
(如stacktrace中的建议)是可行的,但如果有其他选项可用,我宁愿不更改html文件。尝试从进程资源中排除文件会导致问题消失,但也会产生副作用,即也从复制中排除文件:
configure(tasks.processresources) {
exclude 'static/dollar.html'
}
我还看到您可以过滤处理的资源。我想这是我想做的,但是我没有找到“忽略$过滤器”,有吗?
configure(tasks.processresources) {
filesmatching('static/dollar.html') {
filter = ???
}
}
还有其他建议吗?
dollar.html
引起问题的文件可以简化为:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div>Dollar $</div>
</body>
以上是大佬教程为你收集整理的Gradle processResources-文件包含$字符全部内容,希望文章能够帮你解决Gradle processResources-文件包含$字符所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。