How to get the application version programmatically in Compose Desktop?
Asked Answered
B

1

9

I know it's possible to set the version in build.gradlenativeDistributions.packageVersion ...
but how does one read that version in the source code of the app, for example to print it in the application composable?

On macOs the about screen is available when opening the distributable app, and it shows the version we set via build.gradle: enter image description here

Bloodstain answered 3/5, 2022 at 16:40 Comment(1)
As a workaround, for now I'm providing an argument to the nativeDistributions with args += listOf("-v=${rootProject.version}",) and using that in release builds.Bloodstain
C
3

You can try out the following, which will return the package version as String:

System.getProperty("jpackage.app-version")

Note: You should run your application using gradle runDistributable, otherwise the "jpackage.app-version" property will be null.

This will only work if you package and run either by jpackage or compose desktop plugin.

Other way to solve this is by using a Gradle task thst will generate Kotlin code containing the info you need from jpackage or Compose Desktop Gradle task

Crabbe answered 26/7, 2022 at 10:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.