Why can't I access variables from the plugins defi...
# gradle
l
Why can't I access variables from the plugins definition block?
Copy code
val foo = "foo"

plugins {
    val bar = foo // 'val foo: String' can't be called in this context by implicit receiver. Use explicit one if necessary.
}
If I add
this@Build_gradle.
, the error disappears from the code, but I still get an error when I try to build...
It's special.
n
you can use buildSrc to declare varibales that can be used within plugins block
i think you can also access varables from gradle.properties files there
l
oh... ok. That's funny. I can access constants from buildSrc if they are in the root package since I don't have to import them.
n
i usualöly put them in something like Constants.kt and if i need to structure many constants i group whtm in objects
e
@Luke You can also access them if they are in the
org.gradle.kotlin.dsl
package. JVM takes care of importing the so-called default (ie empty) package implicitly, while the gradle kotlin DSL implicitly imports all declarations in
org.gradle.kotlin.dsl
. Thats why the extensions defined in that package work outta the box.