Hello,
variables defined in the settings.gradle.kts cannot be referenced in the plugins block.
A stripped-down sample of by settings.gradle.kts:
val version1 = "1.2.3"
val version2 = "4.5.6"
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
plugins {
id("a.plugin.id") version version1
}
}
dependencyResolutionManagement {
create("libs") {
library("mylib", "org", "name").version(version2)
}
}
In the plugins block I get a reference error as the variable version1 is not found, whereas in the dependencyResolutionManagement block the variable version2 is correctly referenced.
If I move the definition of variable1 inside the plugins block then the settings script works OK.
The same happens if I define the versions in the gradle.properties file and reference them in the settings script like
val version1: String by settings
Again, if the val is defined (by delegation) at the top of the settings file then I get the reference error, while if I put the definition (by delegation) inside the plugins block, then things work OK.
Can someone explain to me what is going on here and if there is a way to obtain what one would consider a ‘normal’ behaviour in a script, i.e. that the variables defined at the outermost scope can be referenced in the inner blocks?
A final remark: I am on gradle 7.4 on Windows 10, kotlin 1.6.20-RC
Thanks a lot,
GP