[英]Is there a Groovy equivalent to Scala's literal identifiers?
Scala's literal identifiers are described in Need clarification on Scala literal identifiers (backticks) . Scala 文字标识符(反引号)中的需要说明中描述了Scala的文字标识符 。
Background: I'm converting an Ant build system to Gradle. 背景:我正在将一个Ant构建系统转换为Gradle。 We currently have a file
dependencies.properties
with definitions like: 当前,我们有一个文件
dependencies.properties
,其定义如下:
com.netflix.archaius.archaius-core.rev=latest.release
But Groovy doesn't like the .
但是Groovy并不喜欢它
.
and -
in the property names (since they're operators). -
在属性名称中(因为它们是运算符)。 Rather than changing the names of the properties and everything using them, is there a way to tell Groovy to consider the .
除了改变属性的名称以及使用它们的所有内容之外,还有一种方法告诉Groovy考虑
.
and -
as simply another character in the property name? 和
-
作为属性名称中的另一个字符?
The following does not provide literal identifiers, as in Scala, but it should solve your root problem. 以下内容不提供Scala中的文字标识符,但它可以解决您的根本问题。 Given this dependencies.properties file:
给定以下dependencies.properties文件:
foo=bar
com.netflix.archaius.archaius-core.rev=latest.release
and then this Gradle script: 然后这个Gradle脚本:
ant.property(file: "dependencies.properties")
task go() {
println ant."com.netflix.archaius.archaius-core.rev"
println ant.foo
println "done."
}
the output is (edited for brevity): 输出是(为简洁起见进行了编辑):
bash-3.2$ gradle go
latest.release
bar
done.
BUILD SUCCESSFUL
Total time: 4.26 secs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.