You can workaround the behavior by adding this block to your settings.gradle. This makes an assumption that you only pass in file names on the -b flag and not paths to a file in a different directory.
if (startParameter.buildFile) {
rootProject.buildFileName = startParameter.buildFile.name
}
The issue has to do with the findAndLoadSettings method on the org.gradle.initialization.SettingsHandler class. Anytime that you change the build file to use through the CLI, it’s going to ignore your settings unless they set the build file to the same thing you specified on the CLI. It does, however, parse the settings, so you will see output if you throw some printlns in there.
Oddly, this seems to work fine if you change the build file in the settings.gradle, but without specifying it on the CLI. So something like this is also an option, but not as nice:
settings.gradle
rootProject.buildFileName = "${buildFile}"
CLI:
gradle -PbuildFile=moved.gradle tasks
At the very least it seems like it would be nice for the build file specified in the StartParameter to be the default on the Settings object, so you don’t need the workaround.