thoredge thoredge - 7 months ago 80
Groovy Question

Dotted strings to properties

I've got a hash of strings similar to this:

Map map = ['a.b.c': 'Hi']

... that I need to use in gradle to expand an expression like this:

This is a greeting: ${a.b.c}

If I use the gradle copy task with expand I will get an error message 'No such property: a'.

Is there any way to get gradle/groovy to convert that map into the properties I need to resolve?


I'm not exactly sure what your needs are, but if you just need to replace property-like tokens and don't need the full power of Groovy templates, the filter() method in combination with Ant's ReplaceTokens class is a safer (and faster) bet than expand(). See Filtering files in the Gradle User Guide.