How/Can 我在 gradle 的 expand/copy 期间将辅助文件包含到文件中?
How/Can I include secondary files into a file during gradle's expand/copy?
我正在尝试制作各种 XML 文件的模板。我想要做的是能够通过包含几个子 XML 文件来构建父 XML。这应该在使用 SimpleTemplateEngine
的 expand()->copy() 期间发生
举个例子:
Gradle:
processResources {
exclude '**/somedir/*'
propList.DESCRIPTION = 'a description goes here'
expand(propList)
}
Parent.XML:
<xml>
<line1>something</line1>
<%include file="Child.XML" %>
</xml>
文档指出 SimpleTemplateEngine 使用 JSP <% 语法和 <%= 表达式,但不一定提供支持的函数列表。
include 失败,因为它不是生成的 SimpleTemplateScript 的有效方法,也许我的意思是 eval?
我最接近开始工作的是:
<xml>
<line1>something</line1>
<% evaluate(new File("Child.xml")) %>
</xml>
这导致 Child.xml 的 404,因为它查看的是进程工作目录,而不是父文件的工作目录。如果我将其引用为 "build/resources/main/templates..../Child.xml",那么在解析子项时会出现 'unexpected token: < @ line....' 错误。
这能做到吗?如果可能的话,我是否需要更改模板引擎?理想情况下,它也应该处理 Child 中的任何标记。
这在 JSP 中非常简单。我以某种方式得到的印象是我可以像对待 GSP 一样对待这些文件,但我不确定如何正确使用 GSP 标签,如果这是真的的话。
一如既往的任何帮助,我们将不胜感激。
谢谢。
This documentation没有提到JSP。 SimpleTemplateEngine
的语法是 ${}
.
使用 Gradle 3.4-rc2,如果我有这个 build.gradle
文件:
task go(type: ProcessResources) {
from('in') {
include 'root.xml'
}
into 'out'
def props = [:]
props."DESCRIPTION" = "description"
expand(props)
}
其中 in/root.xml
是:
<doc>
<name>root</name>
<desc>${DESCRIPTION}</desc>
${new File("in/childA.xml").getText()}
</doc>
和in/childA.xml
是:
<child>
<name>A</name>
</child>
那么输出是:
<doc>
<name>root</name>
<desc>description</desc>
<child>
<name>A</name>
</child>
</doc>
我正在尝试制作各种 XML 文件的模板。我想要做的是能够通过包含几个子 XML 文件来构建父 XML。这应该在使用 SimpleTemplateEngine
的 expand()->copy() 期间发生举个例子:
Gradle:
processResources {
exclude '**/somedir/*'
propList.DESCRIPTION = 'a description goes here'
expand(propList)
}
Parent.XML:
<xml>
<line1>something</line1>
<%include file="Child.XML" %>
</xml>
文档指出 SimpleTemplateEngine 使用 JSP <% 语法和 <%= 表达式,但不一定提供支持的函数列表。
include 失败,因为它不是生成的 SimpleTemplateScript 的有效方法,也许我的意思是 eval?
我最接近开始工作的是:
<xml>
<line1>something</line1>
<% evaluate(new File("Child.xml")) %>
</xml>
这导致 Child.xml 的 404,因为它查看的是进程工作目录,而不是父文件的工作目录。如果我将其引用为 "build/resources/main/templates..../Child.xml",那么在解析子项时会出现 'unexpected token: < @ line....' 错误。
这能做到吗?如果可能的话,我是否需要更改模板引擎?理想情况下,它也应该处理 Child 中的任何标记。
这在 JSP 中非常简单。我以某种方式得到的印象是我可以像对待 GSP 一样对待这些文件,但我不确定如何正确使用 GSP 标签,如果这是真的的话。
一如既往的任何帮助,我们将不胜感激。
谢谢。
This documentation没有提到JSP。 SimpleTemplateEngine
的语法是 ${}
.
使用 Gradle 3.4-rc2,如果我有这个 build.gradle
文件:
task go(type: ProcessResources) {
from('in') {
include 'root.xml'
}
into 'out'
def props = [:]
props."DESCRIPTION" = "description"
expand(props)
}
其中 in/root.xml
是:
<doc>
<name>root</name>
<desc>${DESCRIPTION}</desc>
${new File("in/childA.xml").getText()}
</doc>
和in/childA.xml
是:
<child>
<name>A</name>
</child>
那么输出是:
<doc>
<name>root</name>
<desc>description</desc>
<child>
<name>A</name>
</child>
</doc>