This is pretty common in Java-world having properties files with dot (.) in the key. Maven and Gradle solves this problem naturally but now I need to do this in plain groovy:
def propertiesFileContent = 'a.b=http://my.com/test'
def templateContent = 'Testing ${a.b} '
def props = new Properties()
props.load(new StringReader(propertiesFileContent))
def template = new groovy.text.SimpleTemplateEngine().createTemplate(templateContent)
println template.make(props)
The above code throws exception because the template engine threats ${a.b} as 'b' field of the 'a' object and do not accept 'a.b=http://my.com/test' to substitute. First I thought it is a bug in groovy templating but now it seems that this is a well-known limitation, and everybody suggests solutions that needs the modification of the template:
- Get values from properties file using Groovy
- https://issues.apache.org/jira/browse/GROOVY-8041
- How to access map values in groovy by key containing dot?
I'm in a situation where I should do this without the chance to modify the properties file or the template itself: they are in TAGged and released version of the application :-( Is there a solution or workaround if those are not possible? (I tried to use FreeMarker templating but facing the same issue)