JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

Support explicit dist names #4976

Open Goooler opened 1 week ago

Goooler commented 1 week ago

Now I configure the macOS output dist name like:

compose.desktop {
    application {
        ...
        nativeDistributions {
            targetFormats(TargetFormat.Dmg)

            packageName = "Foo"
            packageVersion = "1.0"
        }
    }
}

This will generate the output dmg files like Foo-1.0.dmg, if I want to rename the dist will set packageName to something like foo-x64, but this will lead the extracted app name to foo-x64-1.0.app, which is not what I expected. Seems I don't find any direct way to leave the dist name and the app name different. It would be great to support this feature.

Goooler commented 1 week ago

Workaround:

/**
 * TODO: workaround for https://github.com/JetBrains/compose-multiplatform/issues/4976.
 */
val renameDmg by tasks.registering(Copy::class) {
    group = "distribution"
    description = "Rename the DMG file"

    val packageDmg = tasks.named<AbstractJPackageTask>("packageDmg")
    // build/compose/binaries/main/dmg/*.dmg
    val fromFile = packageDmg.map {
        it.appImage.get().dir("../dmg").asFile.toPath()
            .listDirectoryEntries("$baseName*.dmg").single()
    }

    from(fromFile)
    into(fromFile.map { it.parent })
    rename {
        "kotlin-explorer-$currentArch-$version.dmg"
    }
}