2
0

desktopApp.gradle.kts 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import org.jetbrains.compose.desktop.application.dsl.TargetFormat
  2. plugins {
  3. alias(libs.plugins.kotlin.jvm)
  4. alias(libs.plugins.compose)
  5. alias(libs.plugins.compose.compiler)
  6. }
  7. kotlin {
  8. jvmToolchain(libs.versions.java.language.version.get().toInt())
  9. }
  10. dependencies {
  11. implementation(projects.shared)
  12. implementation(compose.desktop.currentOs)
  13. }
  14. // IDE run-config compatibility: the old KMP module exposed `desktopRun`; a plain JVM
  15. // Compose Desktop module exposes `run`. Keep `desktopRun` working as an alias.
  16. tasks.register("desktopRun") {
  17. group = "compose desktop"
  18. description = "Alias for :desktopApp:run (IDE run configuration compatibility)."
  19. dependsOn("run")
  20. }
  21. compose.desktop {
  22. application {
  23. jvmArgs("-Dprism.order=sw")
  24. mainClass = "org.mjdev.desktop.main.MainKt"
  25. // jpackage (createDistributable/packageDeb) needs a full JDK; the IDE's bundled JBR
  26. // (e.g. Android Studio's) ships without jpackage, so resolve a jpackage-capable JDK
  27. // explicitly. Override with JPACKAGE_HOME or JAVA_HOME; falls back to system JDKs.
  28. sequenceOf(
  29. System.getenv("JPACKAGE_HOME"),
  30. System.getenv("JAVA_HOME"),
  31. "/usr/lib/jvm/java-21-openjdk-amd64",
  32. "/usr/lib/jvm/java-17-openjdk-amd64",
  33. ).filterNotNull().firstOrNull { rootProject.file("$it/bin/jpackage").canExecute() }
  34. ?.let { javaHome = it }
  35. nativeDistributions {
  36. packageName = libs.versions.app.name.get()
  37. packageVersion = libs.versions.app.pkg.version.get()
  38. description = libs.versions.app.description.get()
  39. copyright = libs.versions.app.copyright.get()
  40. outputBaseDir.set(rootProject.rootDir.resolve("packages"))
  41. linux {
  42. appCategory = libs.versions.app.category.get()
  43. debMaintainer = libs.versions.app.maintainer.get()
  44. menuGroup = libs.versions.app.menu.group.get()
  45. vendor = libs.versions.app.vendor.get()
  46. }
  47. // macOS code signing + notarization. Requires a paid Apple Developer ID certificate
  48. // installed in the build keychain — credentials come from env (CI secrets), never
  49. // hardcoded. With no MACOS_SIGN_IDENTITY the .dmg is built unsigned exactly as before
  50. // (Gatekeeper "open anyway"), so nothing changes until a real certificate is provided.
  51. val macSignIdentity = System.getenv("MACOS_SIGN_IDENTITY")
  52. if (!macSignIdentity.isNullOrBlank()) {
  53. macOS {
  54. bundleID = System.getenv("MACOS_BUNDLE_ID") ?: "org.mjdev.desktop"
  55. signing {
  56. sign.set(true)
  57. identity.set(macSignIdentity)
  58. }
  59. val notaryAppleId = System.getenv("MACOS_NOTARY_APPLE_ID")
  60. val notaryPassword = System.getenv("MACOS_NOTARY_PASSWORD")
  61. val notaryTeamId = System.getenv("MACOS_NOTARY_TEAM_ID")
  62. if (!notaryAppleId.isNullOrBlank() &&
  63. !notaryPassword.isNullOrBlank() &&
  64. !notaryTeamId.isNullOrBlank()
  65. ) {
  66. notarization {
  67. appleID.set(notaryAppleId)
  68. password.set(notaryPassword)
  69. teamID.set(notaryTeamId)
  70. }
  71. }
  72. }
  73. }
  74. targetFormats(
  75. TargetFormat.Deb,
  76. TargetFormat.Rpm,
  77. TargetFormat.AppImage,
  78. TargetFormat.Exe, // Windows installer — only built on a Windows host
  79. TargetFormat.Dmg, // macOS installer — only built on a macOS host
  80. )
  81. buildTypes.release.proguard {
  82. configurationFiles.from("desktopApp.pro")
  83. // optional transitive deps (netty -> log4j2) defeat the optimizer's class
  84. // hierarchy analysis (IncompleteClassHierarchyException); shrink+obfuscate stay on
  85. optimize.set(false)
  86. }
  87. }
  88. }
  89. }