I'm making a multiplatform library and I wanted to...
# gradle
j
I'm making a multiplatform library and I wanted to ask how I could make my actual code read a property from gradle. I have my version defined in
buildSrc/src/main/kotlin/Versions
and I somehow want to access a value from there in my library. How could I do that?
c
There are multiple ways to do it. One of the most common is to have a Gradle task that creates a file in your resources with the version number, and then your application can read it like any other file
v
Besides that, you should consider switching to version catalogs. Even though it wouldn't change the answer to this question. 🙂
j
yea I using version catalogs for everything besides my library version because for some reason the version didn't appear during publishing of the library / ? But otherwise they work
that was the problem:
Copy code
group = "group"
version = libs.versions.project.get() //doesn't work
might be my mistake
v
Oh, I see. Never tried that, I usually have group and version in
gradle.properties
But I would have said this should work too
a
I use version catalogs for my project and it works when set on afterEvaluate
v
yikes, you said the bad word!