Here's my failing build.gradle.kts:
val kotlinVersion by project("kotlinVersion") //Happens without parameters also
buildscript {
repositories {
jcenter()
}
dependencies {
//Property is not visible here
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
allprojects {
repositories {
jcenter()
}
}
Here's the gradle.properties:
kotlinVersion=1.0.4
And here is the whole output.
The buildscript block and the remaining of the script are compiled and executed separately so variables and functions declared outside buildscript block are inaccessible by design.
Number of downvotes suggests that even if "by design" was a reasonable decision at the moment of implementing, it is definitely not what developers are expecting. Any chance you can reconsider something as basic as "I don't want to hardcode magical numbers"? If you do it in the code, any static analysis tool would raise an error for using magical number. Why should gradle scripts be special? I find gradle complicated where it shouldn't and inflexible where it should.
Edit: nevermind. I just saw that there is more active discussion of this problem in this ticket https://github.com/gradle/gradle/issues/1697 and after 2 years of going back and forth a half-measure was added.