Is there a way to access `buildSrc` declarations w...
# gradle
x
Is there a way to access
buildSrc
declarations within your app module?
😶 1
v
Can you elaborate what you mean? Which declarations where and used where exactly?
x
sure - for example, i have a
Configurations.kt
in
buildSrc
where i define a global version for my app and i wish to reference this within my
:app
module. I know you can do this by declaring new
configFields
in build configs like
Copy code
android {
  defaultConfig {
    buildConfigField("String", "VERSION", "\"${Configurations.App.Version}\"")
  }
}
But this is limiting as this is only doable in an android project, whereas my setup is a multiplatform project.
v
So you want to access it at runtime in the production code?
x
yeah
v
You can for example use a
WriteProperties
task to create a properties file with the values you want and then read it at runtime.
Or you can have a template resource file with placeholders, that you still via configuration of
processResources
task
x
hmm, how would you load said
.properties
to each of the modules?
v
What do you mean?
If you need it in multiple modules, have one common that has the file and maybe a class to interpret it that you then can use from the other modules
x
I see, I will post my solution here once i figure it out. thanks for the direction @Vampire.
Found a gradle plugin that lets me do this quite elegantly in a kotlin multi-platform setup.
👌 1