简体   繁体   中英

Is there a Groovy equivalent to Scala's literal identifiers?

Scala's literal identifiers are described in Need clarification on Scala literal identifiers (backticks) .

Background: I'm converting an Ant build system to Gradle. We currently have a file dependencies.properties with definitions like:

com.netflix.archaius.archaius-core.rev=latest.release

But Groovy doesn't like the . 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 . 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. Given this dependencies.properties file:

foo=bar
com.netflix.archaius.archaius-core.rev=latest.release

and then this Gradle script:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM