Groovy: how to test if a property access will be successful?

Use object.hasProperty(propertyName). This will return a truthy value (the property reference) if the property exists. Also object.metaClass.hasProperty(instance, propertyName) is possible. Use object.respondsTo(methodName) to test for method existence.


I do this in my Gradle scripts:

if(project.hasProperty("propertyThatMightExist")){
    use(propertyThatMightExist)
}