0
# Desktop Application Configuration
1
2
The desktop application configuration provides a comprehensive DSL for configuring JVM desktop applications, including packaging, distribution, and platform-specific settings.
3
4
## Desktop Extension
5
6
```kotlin { .api }
7
abstract class DesktopExtension @Inject constructor(
8
private val objectFactory: ObjectFactory
9
) : ExtensionAware {
10
val application: JvmApplication
11
val nativeApplication: NativeApplication
12
fun application(fn: Action<JvmApplication>)
13
fun nativeApplication(fn: Action<NativeApplication>)
14
}
15
```
16
17
## JVM Application Configuration
18
19
```kotlin { .api }
20
abstract class JvmApplication {
21
abstract var mainClass: String?
22
abstract val mainJar: RegularFileProperty
23
abstract var javaHome: String
24
abstract val args: MutableList<String>
25
abstract val jvmArgs: MutableList<String>
26
abstract val nativeDistributions: JvmApplicationDistributions
27
abstract val buildTypes: JvmApplicationBuildTypes
28
29
abstract fun from(from: SourceSet)
30
abstract fun from(from: KotlinTarget)
31
abstract fun disableDefaultConfiguration()
32
abstract fun dependsOn(vararg tasks: Task)
33
abstract fun dependsOn(vararg tasks: String)
34
abstract fun fromFiles(vararg files: Any)
35
abstract fun args(vararg args: String)
36
abstract fun jvmArgs(vararg jvmArgs: String)
37
abstract fun nativeDistributions(fn: Action<JvmApplicationDistributions>)
38
abstract fun buildTypes(fn: Action<JvmApplicationBuildTypes>)
39
}
40
```
41
42
### Basic Application Configuration
43
44
```kotlin
45
compose.desktop {
46
application {
47
mainClass = "com.example.MainKt"
48
49
args("--debug", "--verbose")
50
jvmArgs("-Xmx2g", "-Xms512m")
51
52
from(sourceSets.main.get())
53
dependsOn("processResources")
54
}
55
}
56
```
57
58
## Distribution Configuration
59
60
```kotlin { .api }
61
abstract class JvmApplicationDistributions : AbstractDistributions() {
62
var modules: ArrayList<String>
63
var includeAllModules: Boolean
64
var targetFormats: Set<TargetFormat>
65
val linux: LinuxPlatformSettings
66
val macOS: JvmMacOSPlatformSettings
67
val windows: WindowsPlatformSettings
68
69
fun modules(vararg modules: String)
70
fun targetFormats(vararg formats: TargetFormat)
71
fun linux(fn: Action<LinuxPlatformSettings>)
72
fun macOS(fn: Action<JvmMacOSPlatformSettings>)
73
fun windows(fn: Action<WindowsPlatformSettings>)
74
fun fileAssociation(
75
mimeType: String,
76
extension: String,
77
description: String,
78
linuxIconFile: File? = null,
79
windowsIconFile: File? = null,
80
macOSIconFile: File? = null,
81
)
82
}
83
```
84
85
### Default Runtime Modules
86
87
The default JVM modules included in distributions:
88
89
```kotlin { .api }
90
internal val DEFAULT_RUNTIME_MODULES = arrayOf(
91
"java.base",
92
"java.desktop",
93
"java.logging",
94
"jdk.crypto.ec"
95
)
96
```
97
98
### Distribution Configuration Example
99
100
```kotlin
101
compose.desktop {
102
application {
103
nativeDistributions {
104
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
105
packageName = "MyDesktopApp"
106
packageVersion = "1.0.0"
107
description = "My awesome desktop application"
108
copyright = "© 2024 My Company"
109
vendor = "My Company"
110
111
modules("java.base", "java.desktop", "java.logging", "java.sql")
112
// Or include all modules
113
includeAllModules = true
114
115
// File associations
116
fileAssociation(
117
mimeType = "application/myapp-document",
118
extension = "myapp",
119
description = "MyApp Document"
120
)
121
}
122
}
123
}
124
```
125
126
## Platform-Specific Configuration
127
128
### Linux Configuration
129
130
```kotlin { .api }
131
abstract class LinuxPlatformSettings : JvmPlatformSettings() {
132
abstract var debMaintainer: String
133
abstract var debDescription: String
134
abstract var debPreInst: String?
135
abstract var debPostInst: String?
136
abstract var debPreRm: String?
137
abstract var debPostRm: String?
138
abstract var debCopyright: String?
139
abstract var debLauncher: String?
140
abstract var debPackageVersion: String
141
abstract var menuGroup: String
142
abstract var rpmLicenseType: String
143
abstract var rpmPackageVersion: String
144
abstract var rpmDescription: String
145
abstract var rpmSummary: String
146
abstract var rpmPreInst: String?
147
abstract var rpmPostInst: String?
148
abstract var rpmPreRm: String?
149
abstract var rpmPostRm: String?
150
abstract var appRelease: String
151
abstract var appCategory: String
152
abstract var shortcut: Boolean
153
}
154
```
155
156
Usage example:
157
158
```kotlin
159
compose.desktop {
160
application {
161
nativeDistributions {
162
linux {
163
packageName = "my-desktop-app"
164
debMaintainer = "maintainer@example.com"
165
debDescription = "My awesome desktop application"
166
debCopyright = "© 2024 My Company"
167
debPackageVersion = "1.0.0"
168
menuGroup = "Development"
169
rpmLicenseType = "MIT"
170
rpmDescription = "My awesome desktop application"
171
rpmSummary = "Desktop application built with Compose"
172
appCategory = "Development"
173
shortcut = true
174
175
fileAssociation(
176
mimeType = "application/myapp-document",
177
extension = "myapp",
178
description = "MyApp Document",
179
iconFile = File("src/main/resources/linux-icon.png")
180
)
181
}
182
}
183
}
184
}
185
```
186
187
### macOS Configuration
188
189
```kotlin { .api }
190
abstract class JvmMacOSPlatformSettings : JvmPlatformSettings() {
191
abstract var bundleID: String
192
abstract var packageBuildVersion: String
193
abstract var dmgPackageVersion: String
194
abstract var dmgPackageBuildVersion: String
195
abstract var pkgPackageVersion: String
196
abstract var pkgPackageBuildVersion: String
197
abstract var dockName: String
198
abstract var setDockIconPath: String?
199
abstract var appStore: Boolean
200
abstract var appCategory: String?
201
abstract val signing: MacOSSigningSettings
202
abstract val notarization: MacOSNotarizationSettings
203
abstract val runtime: MacOSRuntimeSettings
204
205
abstract fun signing(fn: Action<MacOSSigningSettings>)
206
abstract fun notarization(fn: Action<MacOSNotarizationSettings>)
207
abstract fun runtime(fn: Action<MacOSRuntimeSettings>)
208
}
209
210
abstract class MacOSSigningSettings {
211
abstract val sign: Property<Boolean>
212
abstract val identity: Property<String>
213
abstract val keychain: Property<String>
214
abstract val prefix: Property<String>
215
abstract val options: ListProperty<String>
216
}
217
218
abstract class MacOSNotarizationSettings {
219
abstract val notarize: Property<Boolean>
220
abstract val appleID: Property<String>
221
abstract val password: Property<String>
222
abstract val teamID: Property<String>
223
abstract val ascProvider: Property<String>
224
}
225
226
abstract class MacOSRuntimeSettings {
227
abstract val jvmArgs: ListProperty<String>
228
}
229
```
230
231
Usage example:
232
233
```kotlin
234
compose.desktop {
235
application {
236
nativeDistributions {
237
macOS {
238
packageName = "MyDesktopApp"
239
bundleID = "com.example.mydesktopapp"
240
packageBuildVersion = "1.0.0"
241
packageVersion = "1.0.0"
242
dmgPackageVersion = "1.0.0"
243
dmgPackageBuildVersion = "1.0.0"
244
dockName = "My App"
245
appCategory = "public.app-category.productivity"
246
247
signing {
248
sign.set(true)
249
identity.set("Developer ID Application: My Company")
250
keychain.set("/path/to/keychain")
251
}
252
253
notarization {
254
notarize.set(true)
255
appleID.set("developer@example.com")
256
password.set("app-specific-password")
257
teamID.set("TEAM123456")
258
}
259
260
runtime {
261
jvmArgs.add("-Xmx2g")
262
jvmArgs.add("-Xms512m")
263
}
264
265
fileAssociation(
266
mimeType = "application/myapp-document",
267
extension = "myapp",
268
description = "MyApp Document",
269
iconFile = File("src/main/resources/macos-icon.icns")
270
)
271
}
272
}
273
}
274
}
275
```
276
277
### Windows Configuration
278
279
```kotlin { .api }
280
abstract class WindowsPlatformSettings : JvmPlatformSettings() {
281
abstract var console: Boolean
282
abstract var dirChooser: Boolean
283
abstract var perUserInstall: Boolean
284
abstract var menuGroup: String
285
abstract var upgradeUuid: String?
286
abstract var msiPackageVersion: String
287
abstract var exePackageVersion: String
288
abstract var shortcut: Boolean
289
abstract var menu: Boolean
290
abstract var installationPath: String?
291
abstract var appUserModelId: String?
292
}
293
```
294
295
Usage example:
296
297
```kotlin
298
compose.desktop {
299
application {
300
nativeDistributions {
301
windows {
302
packageName = "MyDesktopApp"
303
packageVersion = "1.0.0"
304
msiPackageVersion = "1.0.0"
305
exePackageVersion = "1.0.0"
306
console = false
307
dirChooser = true
308
perUserInstall = false
309
menuGroup = "My Company\\Applications"
310
shortcut = true
311
menu = true
312
installationPath = "C:\\Program Files\\MyApp"
313
314
iconFile.set(project.file("src/main/resources/windows-icon.ico"))
315
upgradeUuid = "unique-upgrade-uuid"
316
317
fileAssociation(
318
mimeType = "application/myapp-document",
319
extension = "myapp",
320
description = "MyApp Document",
321
iconFile = File("src/main/resources/windows-icon.ico")
322
)
323
}
324
}
325
}
326
}
327
```
328
329
## Build Types
330
331
```kotlin { .api }
332
abstract class JvmApplicationBuildTypes @Inject constructor(
333
objects: ObjectFactory
334
) {
335
val release: JvmApplicationBuildType
336
fun release(fn: Action<JvmApplicationBuildType>)
337
}
338
339
abstract class JvmApplicationBuildType @Inject constructor(
340
internal val classifier: String,
341
objects: ObjectFactory,
342
) {
343
val proguard: ProguardSettings
344
fun proguard(fn: Action<ProguardSettings>)
345
}
346
```
347
348
### Build Type Configuration
349
350
```kotlin
351
compose.desktop {
352
application {
353
buildTypes {
354
release {
355
proguard {
356
isEnabled.set(true)
357
configurationFiles.from("proguard-rules.pro")
358
optimize.set(true)
359
obfuscate.set(true)
360
}
361
}
362
}
363
}
364
}
365
```
366
367
## Native Application
368
369
```kotlin { .api }
370
abstract class NativeApplication {
371
// Configuration for native (non-JVM) applications
372
}
373
```
374
375
Configure native applications:
376
377
```kotlin
378
compose.desktop {
379
nativeApplication {
380
// Native application configuration
381
}
382
}
383
```
384
385
## Generated Tasks
386
387
When you configure a desktop application, the plugin automatically creates tasks:
388
389
- `run` - Run the application
390
- `createDistributable` - Create a distributable directory
391
- `packageDmg` - Create macOS DMG package
392
- `packageMsi` - Create Windows MSI installer
393
- `packageDeb` - Create Linux DEB package
394
- `packageRpm` - Create Linux RPM package
395
- `packageUberJarForCurrentOS` - Create uber JAR for current OS
396
- `runRelease` - Run release build (with ProGuard if enabled)
397
- `createReleaseDistributable` - Create release distributable
398
- `packageReleaseDmg` - Create release DMG package
399
- And similar tasks for other formats and build types