Project properties - more terse way to handle this?

we want to check for project properties, we tried this:

def nodeNumber ='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") ?['node'] : '1'

this works, but it’s kind of long winded, not DRY.

any better approach?


You can use ‘ ?: 1’.

One thing to bare in mind is that ‘’ can be a little expensive to calculate (but rarely significantly) so if you’re doing this a lot then save ‘’ to a temp var. Each time you call ‘’ it has to recalculate as more properties may have been added.

we can’t do that approach because of this side-effect:

sounds like what i pasted is the best way for now…?

Yeah, that’s the best way because of that bug.