Hey guys, how to declare a function inside project...
# gradle
f
Hey guys, how to declare a function inside project build.gradle and use it inside app build gradle, it was possible with Groovy
b
Declare it in your buildSrc
f
Is there a way to do this without buildSrc only from within gradle files?
v
Hey guys, how to declare a function inside project build.gradle and use it inside app build gradle, it was possible with Groovy
You are talking abouto
build.gradle
, so that is Groovy, or do you mean
build.gradle.kts
?
f
.kts Sorry for the confusion
v
Disclaimer: Every time you use extra properties you should feel very dirty and consider doing it properly instead of a hack-around which almost all usages of extra properties are. In the root build file
Copy code
var bar: () -> Unit by extra
bar = {
    println("BAR")
}
In the subproject build file
Copy code
val bar: () -> Unit by project
bar()
f
The thing i want to do is create a function that i can invoke inside the
android{}
to enable compose and apply the composeVersion from TOML libs versioning
The function i want it declared inside the root gradle kts and reuse it in each android submodule where compose needs to be enabled
v
And I told you that you should not do it and how to do it nevertheless, so what's your point?
f
The way to enable these properties should be coming from one function,no? Imagine one day having to change each of these separately, sure thing it can be used find and replace but for readability and robustness it should be controlled from one place i think
v
I don't know what you mean
c
@FunkyMuse the point was to not use
extra
but but your function in a
buildSrc
module
🙏 1
👍 1