I have a .gradle in which I want to set some project properties if a condition is true.
def isRelease = project.getProperty('isRelease')
if (isRelease) {
println 'Detected a release'
project.properties.'releaseCenter'.'uploadURL' = project.properties.'uatUploadURL'
}
The output is:
A problem occurred evaluating root project 'tasks'.
> Cannot set property 'uploadURL' on null object
I think it has to do with the '' around the object name but I couldn't get it to work. Any help is much appreciated.
You call project.properties
: https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getProperties--
which returns a Map
. You then call properties.'releaseCenter'
which is equivalent to doing properties.get("releaseCenter")
which returns null
. You try to get a property on a null
object which is exactly the error you are seeing.
Possible solutions: