2
0

desktopApp.gradle.kts 4.5 KB

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