Ext {} properties and -P overrides

Been searching the forums for this simple thing but haven’t found a definite answer.

Given the following build.gradle:

ext {
    myProperty = 'value'
}

I have always been under the impression that you could override the value simply by stating a new value in gradle.properties or using -PmyProperty... on cmd.

ext {
    myProperty = findProperty('myProperty') ?: 'value'
}

I’ve moved some projects to Gradle 3.3 and I was supprised that I had to use findProperty('mProperty') ?: ... in order to get it to work.

Working with findProperty works great and makes for more readable builds IMHO so it’s all ok but the question still bugs me…

Have I been wrong the whole time or have this changed?

Thnx
Patrik

I don’t think this was ever different. The ext- block in your first example is overwriting whatever the user specified. Using findProperty and a default value as in your second example is the way to go.

1 Like