We want to make our Gradle plugin (8.1.1) compatible with Configuration Cache, so we need a way to pass some Project properties into classes.
We tried to use ProjectLayout, but that does not store properties needed by some classes, only a few of the paths can be used.
We’ve tried using a MapProperty:
abstract MapProperty<String, Object> getProperties()
But when we use any method to get a specific property in this way either with:
getProperties().getting(KEY).isPresent() or getProperties().getting(KEY).getting().get()
we get the following error
"Cannot get the value of a property of type java.util.Map with value type java.lang.Object as the source contains a null value for key <first_key_in_map>"
The Property is set in the calling class with:
Map properties = [:]
object.options.each { property ->
properties[property] = project.findProperty(property)
}
object.properties.set(properties )
where the object
is the class with the Map property, options
is an array with the keys that we want in the class from the properties of Project.
When we run getProperties().keySet().get()
we get no error and we get the keys successfully, but we can’t get the values of the keys.
Does anybody have an idea what is wrong / where we went wrong?
Thanks in advance,
Jos Vermeijlen.