gpt4 book ai didi

Gradle processResources - 文件包含 $ 字符

转载 作者:行者123 更新时间:2023-12-02 06:32:40 24 4
gpt4 key购买 nike

如何在包含 $ 字符的文件上执行 gradle processResources 而不转义文件中的 $

<小时/>

按照 Spring Boot reference docs 的建议,我有一些静态 html 文件位于 /resources/static 文件夹中。 。但是,当我尝试执行 gradle processResources 时,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>

据我了解,出现此问题的原因是其中一个静态文件中有一个 $ 字符,而 $ 是处理资源时表达式的保留字符。

<小时/>

建议的解决方案:

  1. 是的,使用 \$ 转义 $ (如堆栈跟踪中的建议)是可行的,但如果有其他选项可用,我宁愿不更改 html 文件。<
  2. 尝试从进程资源中排除该文件会导致问题消失,但会产生副作用,即也会排除该文件的复制:

    configure(tasks.processResources) {
    exclude 'static/dollar.html'
    }
  3. 我还发现您可以过滤已处理的资源。我想这就是我想做的,但我还没有找到“忽略 $ 过滤器”,有吗?

    configure(tasks.processResources) {
    filesMatching('static/dollar.html') {
    filter = ???
    }
    }
  4. 还有其他建议吗?

<小时/>

导致问题的 dollar.html 文件可以简化为:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div>Dollar $</div>
</body>

最佳答案

JB Nizet's comment提供了宝贵的见解。该问题确实是由于使用 expand() (尽管不是立即可见,因为它位于父项目的 allProjects() 脚本中)。首先添加 expand() 的原因是希望填充 info.build.* application.properties 文件中的属性(以便可以通过 Spring Boot 的 info endpoint 使用它们)。

<小时/>

解决方案:使用filesMatching()expand()选定的文件。以下代码片段解决了与 Spring Boot 相关的特定问题:

processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}

关于Gradle processResources - 文件包含 $ 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com