0

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?

Community
  • 1
  • 1
Noel Yap
  • 18,822
  • 21
  • 92
  • 144
  • 1
    Could [this doc](http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html) and [this discussion](http://gradle.1045684.n5.nabble.com/Load-properties-from-an-arbitrary-properties-file-td3408710.html) help? You can very well use GString implementations where you see `-`. For eg: `com.netflix.archaius.'archaius-core'.rev=${latest.release}` – dmahapatro Jul 19 '13 at 17:45
  • 1
    Why aren't you just parsing the properties file as a properties file, and, if necessary, do some simple string replacement on the resulting map? – Peter Niederwieser Jul 19 '13 at 20:45

1 Answers1

1

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
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
  • In our build, the properties get put in the `project` scope so either `project.'com.netflix.archaius.archaius-core.rev'` or `project[''com.netflix.archaius.archaius-core.rev']` works. – Noel Yap Jul 22 '13 at 17:35