Get values from properties file using Groovy

It looks to me you complicate things too much.

Here’s a simple example that should do the job:

For given test.properties file:

a=1
b=2

This code runs fine:

Properties properties = new Properties()
File propertiesFile = new File('test.properties')
propertiesFile.withInputStream {
    properties.load(it)
}

def runtimeString = 'a'
assert properties."$runtimeString" == '1'
assert properties.b == '2'

Leave a Comment