Any idea how to retrieve the version defined in bu...
# getting-started
l
Any idea how to retrieve the version defined in build.gradle.kts so that i can use it in my code ?
i wanted to try org.gradle.api.getVersion() but gradle is an unresolved reference so i’m doing something wrong. i’m not even sure i’m supposed to do that or not
h
there is no built-in option since Java/Jvm/Kotlin does not know anything about the build system at runtime. But you simply could put the version into a Kotlin file and add this file to your srcDir
l
thank you
h
Another option is the manifest file, but AFAIK a code constant should be more performant than reading the manifest file at runtime
l
no it’s ok. and i’m using kotlin/JS so it’s even worse 🙂
y
You could also use the magnificent BuildConfig plugin which allows you to declare constants in your gradle build file that are then visible inside your code. It's great if you need access to your package/version number/etc.
👍 1
l
there is even a kts js exemple. nice ! thank you
it worked 🥰
789 Views