Project properties - more terse way to handle this?

(Phil Swenson) #1

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?


(Luke Daley) #2

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.

(Phil Swenson) #3

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

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

(Luke Daley) #4

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