:question: How can I access `packageName` defined ...
# compose-desktop
t
How can I access
packageName
defined inside
build.gradle.kts
inside
main
method? Is there any API available?
j
This sounds more like a gradle question, I'd probably suggest asking in some gradle forums.
s
There are couple of ways you can achieve this. • Pass it as JVM args and read it using
System.getProperty()
• Pass it as application args . Here is how i am passing the project , kotlin version, group id and main class
Copy code
compose.desktop {
    application {
        mainClass = "aaa.xxxx.yyyy.AppKt"
        args(
            project.version.toString(),
            kotlin.coreLibrariesVersion,
            project.group.toString(),
            mainClass.toString()
        )
From the App.kt main, you can read it as
args[0], args[1]
etc
t
Ohhh, that's nice. Thanks suresh 🇮🇳
d
I write a .prperties file with gradle stuff after gradle task
processResources
and include it in the jar (don't forget to put the src/main/resources/buildProperties.properties file in your
.gitignore
Copy code
val processResources by tasks.existing {
    val writeProperties by tasks.existing
    finalizedBy(writeProperties)
}
val writeProperties by tasks.registering {
    doLast {
        val srcResourcesProperties = File(projectDir, "src/main/resources/buildProperties.properties")
        val buildResourcesProperties = File(project.buildDir, "resources/main/buildProperties.properties")

        for (propFile in listOf(srcResourcesProperties, buildResourcesProperties)) {
            propFile.printWriter().use { out ->
                out.println("projectDir=${projectDir}")
                out.println("projectDirEcore=${project(":ecore").projectDir}")
                out.println("projectDirBackendServer=${project(":backend:server").projectDir}")
                out.println("projectDirDalcommon=${project(":common:dalcommon").projectDir}")
                out.println("projectDirFrontendUI=${project(":frontend:ui").projectDir}")
            }
        }
    }
}
Copy code
init {
        try {
            buildProperties.load(ClassLoader.getSystemResourceAsStream("buildProperties.properties"))
        } catch (e: Exception) {
            System.err.println("cannot load buildProperties.properties that should have been generated by gradle in custom task ':generators:writeProperties'")
        }
        projectDir = File(buildProperties.getProperty("projectDir"))
        projectDirEcore = File(buildProperties.getProperty("projectDirEcore"))
        projectDirBackendServer = File(buildProperties.getProperty("projectDirBackendServer"))
        projectDirDalcommon = File(buildProperties.getProperty("projectDirDalcommon"))
        projectDirFrontendUI = File(buildProperties.getProperty("projectDirFrontendUI"))
}
👍 1