https://kotlinlang.org logo
#gradle
Title
# gradle
a

Anuta Vlad Sv

02/07/2023, 9:05 AM
Hi! Can anyone tell me how to read value of library version from
libs.versions.toml
in kotlin file [need to send lib-version to BE]?
This is what I have tried so far, but I will need the version value in a different module(app or core).
```class AndroidxComposeVersion : Plugin<Project> {
override fun apply(target: Project) {
target.version()
}
}
fun Project.version(): String {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
return libs.findVersion("androidxCompose").get().toString()
}```
c

CLOVIS

02/07/2023, 9:08 AM
Can't you just
libs.versions.androidxCompose.get()
?
a

Anuta Vlad Sv

02/07/2023, 9:13 AM
I can only see examples with this approach used in gradle files, what I need to do is take the version of a library and send it to the backend.
Actually I can have something like this buildConfigField "String", "COMPOSE_VERSION", "\"${libs.versions.androidxCompose.get()}\"" and in kotlin file I can use BuildConfig.COMPOSE_VERSION Thanks for the suggestion!
m

mbonnin

02/07/2023, 2:39 PM
Beware this will give you the declared version of the compose runtime. If any other library needs a more recent version, what you declare is not always what will end up being used at runtime
25 Views