we want to check for project properties, we tried this:
def nodeNumber = project.property('node') ?: 1
This throws an error: Could not find property ‘node’ on project
How can I check for a property that doesn’t throw an error? I could do a
def nodeNumber = project.hasProperty('node") ? project.property['node'] : '1'
this works, but it’s kind of long winded, not DRY.
any better approach?
thanks
You can use ‘project.properties.node ?: 1’.
One thing to bare in mind is that ‘project.properties’ can be a little expensive to calculate (but rarely significantly) so if you’re doing this a lot then save ‘project.properties’ to a temp var. Each time you call ‘project.properties’ it has to recalculate as more properties may have been added.
we can’t do that approach because of this side-effect:
http://gsfn.us/t/3x4g0
sounds like what i pasted is the best way for now…?
Yeah, that’s the best way because of that bug.