Gradle multiproject, ext {} at top fails?

I can’t figure out why the order of ext {} matters and causes a failure such as below? Without an example to copy, how are you guys figuring the order to put things? The docs seem to just talk about the closures in isolation and not interdependencies between them ?

project-base
    settings.gradle
    build.gradle (inside this one in examples below)
  subproject_folder
    build.gradle


ext {} // this blows up here

 buildscript {}

 plugins {}

 sonarqube {} 

 allprojects {}

 subprojects {}

but if I have the same thing except

buildscript {}

plugins {}

sonarqube {}

allprojects {}

subprojects {}

ext {} // bingo all of a sudden this is legal ?

The specific order of the ext block doesn’t matter here as long as you don’t violate the rules imposed by the plugins block.

The plugins block must be at the top and can only be preceded by the buildscript block. Both plugins and buildscript contribute to the classpath of the build script itself. Therefore, they must be compiled and executed before the rest of the script. That result is then used to compile and execute the rest of the file.

Atleast for kotlin DSL this works. Extra properties can be defined above the plugins block

val myprop1 by project.extra { "somevalue" }

ext {
   set("foo", "bar")
}
println(project.extra["foo"])
println(project.extra["myprop1"])
println(project.ext["foo"])
plugin {
    kotlin("jvm") version("1.3.20")
}

Should print
> Configure project :
hello
bar
bar