0
# Gradle Plugin
1
2
The Compose Multiplatform Gradle plugin provides build system integration and dependency management for Compose projects. It configures compilation for different platforms, manages dependencies, handles resource processing, and provides application packaging for desktop platforms.
3
4
## Capabilities
5
6
### Plugin Application
7
8
Apply the Compose plugin to enable multiplatform Compose development.
9
10
```kotlin { .api }
11
// In build.gradle.kts
12
plugins {
13
id("org.jetbrains.compose") version "1.8.2"
14
}
15
16
// Repository setup
17
repositories {
18
jetbrainsCompose() // Extension function that adds JetBrains Compose repository
19
}
20
```
21
22
### Compose Extension
23
24
Root configuration extension for the plugin.
25
26
```kotlin { .api }
27
/**
28
* Root extension for configuring Compose plugin
29
*/
30
abstract class ComposeExtension {
31
abstract val desktop: DesktopExtension
32
abstract val resources: ResourcesExtension
33
abstract val web: WebExtension
34
abstract val android: AndroidExtension
35
abstract val dependencies: Dependencies
36
37
@Deprecated("Use Kotlin Multiplatform plugin configuration")
38
abstract val kotlinCompilerPlugin: Property<String?>
39
40
@Deprecated("Use Kotlin Multiplatform plugin configuration")
41
abstract val kotlinCompilerPluginArgs: ListProperty<String>
42
}
43
```
44
45
### Desktop Application Configuration
46
47
Configure desktop applications with packaging and distribution options.
48
49
```kotlin { .api }
50
/**
51
* Desktop extension for configuring desktop applications
52
*/
53
abstract class DesktopExtension {
54
abstract val application: JvmApplication
55
abstract val nativeApplication: NativeApplication
56
57
fun application(configure: Action<JvmApplication>)
58
fun nativeApplication(configure: Action<NativeApplication>)
59
}
60
61
/**
62
* JVM application configuration for desktop apps
63
*/
64
abstract class JvmApplication {
65
/** Main class for the application */
66
abstract var mainClass: String?
67
68
/** Main JAR file property */
69
abstract val mainJar: RegularFileProperty
70
71
/** Java installation path */
72
abstract var javaHome: String
73
74
/** Application command line arguments */
75
abstract val args: MutableList<String>
76
77
/** JVM command line arguments */
78
abstract val jvmArgs: MutableList<String>
79
80
/** Distribution configuration */
81
abstract val nativeDistributions: JvmApplicationDistributions
82
83
/** Build types configuration */
84
abstract val buildTypes: JvmApplicationBuildTypes
85
86
/** Configure from source set or Kotlin target */
87
fun from(from: SourceSet)
88
fun from(from: KotlinTarget)
89
90
/** Disable default configuration */
91
fun disableDefaultConfiguration()
92
93
/** Add task dependencies */
94
fun dependsOn(vararg tasks: Task)
95
fun dependsOn(vararg tasks: String)
96
97
/** Configure from files */
98
fun fromFiles(vararg files: Any)
99
100
/** Set application arguments */
101
fun args(vararg args: String)
102
103
/** Set JVM arguments */
104
fun jvmArgs(vararg jvmArgs: String)
105
106
/** Configure distributions */
107
fun nativeDistributions(configure: Action<JvmApplicationDistributions>)
108
109
/** Configure build types */
110
fun buildTypes(configure: Action<JvmApplicationBuildTypes>)
111
}
112
```
113
114
**Usage Example:**
115
116
```kotlin
117
compose {
118
desktop {
119
application {
120
mainClass = "com.example.MainKt"
121
122
args("--debug", "--config=prod")
123
jvmArgs("-Xmx2G", "-Dfile.encoding=UTF-8")
124
125
nativeDistributions {
126
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
127
packageName = "MyApplication"
128
packageVersion = "1.0.0"
129
description = "My Compose Desktop Application"
130
vendor = "Example Corp"
131
132
macOS {
133
bundleID = "com.example.myapp"
134
signing {
135
sign.set(true)
136
identity.set("Developer ID Application: Example Corp")
137
}
138
}
139
140
windows {
141
console = false
142
shortcut = true
143
menu = true
144
}
145
146
linux {
147
shortcut = true
148
packageName = "my-application"
149
appCategory = "Utility"
150
}
151
}
152
153
buildTypes {
154
release {
155
proguard {
156
isEnabled.set(true)
157
obfuscate.set(true)
158
optimize.set(true)
159
}
160
}
161
}
162
}
163
}
164
}
165
```
166
167
### Distribution Configuration
168
169
Configure application packaging and distribution for different platforms.
170
171
```kotlin { .api }
172
/**
173
* Distribution configuration for JVM applications
174
*/
175
abstract class JvmApplicationDistributions : AbstractDistributions {
176
/** Runtime modules to include */
177
abstract val modules: ArrayList<String>
178
179
/** Include all runtime modules */
180
abstract var includeAllModules: Boolean
181
182
/** Linux platform settings */
183
abstract val linux: LinuxPlatformSettings
184
185
/** macOS platform settings */
186
abstract val macOS: JvmMacOSPlatformSettings
187
188
/** Windows platform settings */
189
abstract val windows: WindowsPlatformSettings
190
191
/** Set target distribution formats */
192
fun targetFormats(vararg formats: TargetFormat)
193
194
/** Add runtime modules */
195
fun modules(vararg modules: String)
196
197
/** Configure Linux settings */
198
fun linux(configure: Action<LinuxPlatformSettings>)
199
200
/** Configure macOS settings */
201
fun macOS(configure: Action<JvmMacOSPlatformSettings>)
202
203
/** Configure Windows settings */
204
fun windows(configure: Action<WindowsPlatformSettings>)
205
206
/** Configure file associations for all platforms */
207
fun fileAssociation(
208
mimeType: String,
209
extension: String,
210
description: String,
211
iconFile: File? = null
212
)
213
}
214
215
/**
216
* Available distribution formats
217
*/
218
enum class TargetFormat {
219
/** Application image (cross-platform) */
220
AppImage,
221
/** Debian package (Linux) */
222
Deb,
223
/** RPM package (Linux) */
224
Rpm,
225
/** Disk image (macOS) */
226
Dmg,
227
/** Package installer (macOS) */
228
Pkg,
229
/** Executable installer (Windows) */
230
Exe,
231
/** MSI installer (Windows) */
232
Msi;
233
234
/** Check if format is compatible with current OS */
235
val isCompatibleWithCurrentOS: Boolean
236
237
/** Output directory name for the format */
238
val outputDirName: String
239
240
/** File extension for the format */
241
val fileExt: String
242
}
243
```
244
245
### Platform-Specific Settings
246
247
Configure platform-specific packaging options.
248
249
```kotlin { .api }
250
/**
251
* Linux platform settings
252
*/
253
abstract class LinuxPlatformSettings : AbstractPlatformSettings {
254
/** Create desktop shortcut */
255
abstract var shortcut: Boolean
256
257
/** Linux package name (may differ from main package name) */
258
abstract var packageName: String?
259
260
/** Application release version */
261
abstract var appRelease: String?
262
263
/** Application category for app stores */
264
abstract var appCategory: String?
265
266
/** Debian package maintainer */
267
abstract var debMaintainer: String?
268
269
/** Menu group for application menu */
270
abstract var menuGroup: String?
271
272
/** RPM license type */
273
abstract var rpmLicenseType: String?
274
275
/** Debian package version */
276
abstract var debPackageVersion: String?
277
278
/** RPM package version */
279
abstract var rpmPackageVersion: String?
280
}
281
282
/**
283
* Windows platform settings
284
*/
285
abstract class WindowsPlatformSettings : AbstractPlatformSettings {
286
/** Show console window */
287
abstract var console: Boolean
288
289
/** Show directory chooser during installation */
290
abstract var dirChooser: Boolean
291
292
/** Per-user installation instead of system-wide */
293
abstract var perUserInstall: Boolean
294
295
/** Create desktop shortcut */
296
abstract var shortcut: Boolean
297
298
/** Create start menu entry */
299
abstract var menu: Boolean
300
301
/** Start menu group */
302
abstract var menuGroup: String?
303
304
/** UUID for upgrade identification */
305
abstract var upgradeUuid: String?
306
307
/** MSI package version */
308
abstract var msiPackageVersion: String?
309
310
/** EXE package version */
311
abstract var exePackageVersion: String?
312
}
313
314
/**
315
* macOS platform settings
316
*/
317
abstract class JvmMacOSPlatformSettings : AbstractMacOSPlatformSettings {
318
/** Application name in dock */
319
abstract var dockName: String?
320
321
/** Use package name as dock name */
322
abstract var setDockNameSameAsPackageName: Boolean
323
324
/** App Store compatibility mode */
325
abstract var appStore: Boolean
326
327
/** Entitlements file for code signing */
328
abstract val entitlementsFile: RegularFileProperty
329
330
/** Runtime entitlements file */
331
abstract val runtimeEntitlementsFile: RegularFileProperty
332
333
/** PKG package version */
334
abstract var pkgPackageVersion: String?
335
336
/** PKG build version */
337
abstract var pkgPackageBuildVersion: String?
338
339
/** Provisioning profile for distribution */
340
abstract val provisioningProfile: RegularFileProperty
341
342
/** Runtime provisioning profile */
343
abstract val runtimeProvisioningProfile: RegularFileProperty
344
345
/** Info.plist settings */
346
abstract val infoPlistSettings: InfoPlistSettings
347
348
/** Configure Info.plist */
349
fun infoPlist(configure: Action<InfoPlistSettings>)
350
}
351
```
352
353
### ProGuard Configuration
354
355
Configure code obfuscation and optimization for release builds.
356
357
```kotlin { .api }
358
/**
359
* ProGuard settings for code obfuscation and optimization
360
*/
361
abstract class ProguardSettings {
362
/** ProGuard version to use */
363
abstract val version: Property<String> // default: "7.7.0"
364
365
/** Maximum heap size for ProGuard */
366
abstract val maxHeapSize: Property<String?>
367
368
/** ProGuard configuration files */
369
abstract val configurationFiles: ConfigurableFileCollection
370
371
/** Enable ProGuard processing */
372
abstract val isEnabled: Property<Boolean> // default: false
373
374
/** Enable code obfuscation */
375
abstract val obfuscate: Property<Boolean> // default: false
376
377
/** Enable bytecode optimization */
378
abstract val optimize: Property<Boolean> // default: true
379
380
/** Join output JARs into single file */
381
abstract val joinOutputJars: Property<Boolean> // default: false
382
}
383
```
384
385
### Resources Configuration
386
387
Configure resource generation and processing.
388
389
```kotlin { .api }
390
/**
391
* Configuration for Compose Resources
392
*/
393
abstract class ResourcesExtension {
394
/** Whether generated resources class should be public */
395
abstract var publicResClass: Boolean // default: false
396
397
/** Package for generated Res class */
398
abstract var packageOfResClass: String
399
400
/** Name of generated resources class */
401
abstract var nameOfResClass: String // default: "Res"
402
403
/** Resource class generation mode */
404
abstract var generateResClass: ResourceClassGeneration
405
406
/** Associate custom resource directory with source set */
407
fun customDirectory(
408
sourceSetName: String,
409
directoryProvider: Provider<Directory>
410
)
411
}
412
413
/**
414
* Resource class generation modes
415
*/
416
enum class ResourceClassGeneration {
417
/** Generate based on project configuration */
418
Auto,
419
/** Always generate resources class */
420
Always,
421
/** Never generate resources class */
422
Never
423
}
424
```
425
426
### Dependency Management
427
428
Access Compose library dependencies through the plugin.
429
430
```kotlin { .api }
431
/**
432
* Provides access to Compose library dependencies
433
*/
434
abstract class Dependencies {
435
/** Desktop-specific dependencies */
436
abstract val desktop: DesktopDependencies
437
438
// Core Compose libraries
439
abstract val animation: String
440
abstract val animationGraphics: String
441
abstract val foundation: String
442
abstract val material: String
443
abstract val material3: String
444
abstract val runtime: String
445
abstract val runtimeSaveable: String
446
abstract val ui: String
447
abstract val uiTest: String
448
abstract val uiTooling: String
449
abstract val uiUtil: String
450
abstract val preview: String
451
abstract val materialIconsExtended: String
452
453
/** Component libraries */
454
abstract val components: CommonComponentsDependencies
455
456
/** HTML/Web libraries */
457
abstract val html: HtmlDependencies
458
}
459
460
/**
461
* Desktop-specific dependencies
462
*/
463
object DesktopDependencies {
464
/** Desktop components */
465
val components: DesktopComponentsDependencies
466
467
/** Common desktop dependency */
468
val common: String
469
470
/** Current OS dependency (automatically selected) */
471
val currentOs: String
472
473
// Platform-specific dependencies
474
val linux_x64: String
475
val linux_arm64: String
476
val windows_x64: String
477
val windows_arm64: String
478
val macos_x64: String
479
val macos_arm64: String
480
481
/** Desktop UI testing */
482
val uiTestJUnit4: String
483
}
484
```
485
486
### Extension Functions
487
488
Utility functions for dependency and repository management.
489
490
```kotlin { .api }
491
/**
492
* Add JetBrains Compose repository
493
*/
494
fun RepositoryHandler.jetbrainsCompose(): MavenArtifactRepository
495
496
/**
497
* Helper functions for adding Compose dependencies
498
*/
499
fun KotlinDependencyHandler.compose(groupWithArtifact: String): String
500
fun DependencyHandler.compose(groupWithArtifact: String): String
501
```
502
503
### Annotations
504
505
```kotlin { .api }
506
/**
507
* Marks experimental Compose library APIs
508
*/
509
@RequiresOptIn
510
annotation class ExperimentalComposeLibrary
511
```