Project properties in initialization script

Today I was working on migrating an initialization script from one environment to another. One of the things our script does it downloads a gradle file from a remote server that sets up generic environment settings . Currently the script looks something like this:

initscript.gradle
if(project.hasProperty(‘buildUrl’) {
apply from: “${buildUrl}”
}

The build.gradle:

buildscript { apply from: file('initscript.gradle') }

In the projects gradle.properties the url is set

buildUrl=http://servername/path/to/apply.gradle

In the new environment, we were hoping to use a run time argument, in other words:

-PbuildUrl=http://newserver/path/to/apply.gradle

However the initialization script is just using the value in the gradle.properties.

Based on the documentation for the build phases, this seems to be expected. However I have the following questions:

  1. Why does the property get set in the first place? From the documentation I would have expected the property to have been unset.
  2. Is there any way to override a property that can then be used in the init script?

Currently I have a workaround; I’m going to update the script to also check an environment variable.