Hi guys, quick question - is there anything like `...
# gradle
l
Hi guys, quick question - is there anything like
gradle.ext
that I can use to make values from settings.gradle.kts available to build.gradle.kts?
c
add to ext:
val yourValue by extra { "some value" }
declare in a file you want to access it in:
val yourValue: String by extra
access it:
println("Just got a value from extra: $yourValue")
I don't remember for sure, but if the above doesn't work, try
gradle.extra
instead of just
extra
.
l
Yeah I know about extra, but that seems to be unavailable in
settings.gradle.kts
?
r
Don't know if it suits you, but as a workaround for constants (and not only for them, actually) there was a following solution suggested yesterday: https://kotlinlang.slack.com/archives/C19FD9681/p1513272845000259?thread_ts=1513272693.000251&cid=C19FD9681
c
@lukas does this
gradle.extra["something"] = "something"
work?
l
@r4zzz4k Thank you for the suggestions, I’ll check it out. Not sure if that’s what I need though, since I am passing dynamic data..
@Czar No it does not,
gradle.extra
can’t be resolved (since
Gradle
is not
ExtensionAware
)
r
What kind of data though? Is it really tied to
Project
instance?
buildSrc
is still a valid place for a bit more involved building logic global for the project. Of course I'm not saying that you don't need extras, it depends :)
l
It’s a dynamic multi-project build with shared data, so I generate that once in settings.gradle and then can access it from all project builds. Since the included projects can vary, I don’t know if buildSrc can help me. Thank you for your help 🙂
c
Copy code
// in settings.gradle.kts
gradle.beforeProject {
        extra["meow"] = "meowValue"
        // or: val meow: String by extra { "meowValue" }
}
Copy code
// in build.gradle.kts
val meow: String by extra
this works for me
👍 1
l
Thank you! it works in
beforeProject
🙂
😉 1