Declarative framework for sharing UIs across multiple platforms with Kotlin, including Gradle plugin, component libraries, and web support
npx @tessl/cli install tessl/maven-compose-multiplatform@1.8.0Compose Multiplatform is a declarative framework for sharing UIs across multiple platforms with Kotlin. It enables developers to build native applications for iOS, Android, Desktop (Windows, macOS, Linux), and Web platforms using a single Kotlin codebase. Based on Jetpack Compose, it provides a unified API for creating responsive, modern user interfaces with platform-specific optimizations.
id("org.jetbrains.compose") in your build.gradle.ktsPlugin application:
plugins {
id("org.jetbrains.compose") version "1.8.2"
}
repositories {
jetbrainsCompose()
}Dependency management:
dependencies {
implementation(compose.desktop.currentOs)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.html.core)
}// Apply plugin and configure desktop application
plugins {
id("org.jetbrains.compose")
}
compose {
desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "MyApp"
packageVersion = "1.0.0"
}
}
}
resources {
publicResClass = false
nameOfResClass = "Res"
generateResClass = auto
}
}
dependencies {
implementation(compose.desktop.currentOs)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
}Compose Multiplatform consists of several key components:
Complete build system integration for Compose Multiplatform projects, providing application packaging, dependency management, and platform-specific configurations.
// Plugin extension
abstract class ComposeExtension {
abstract val desktop: DesktopExtension
abstract val resources: ResourcesExtension
abstract val web: WebExtension
}
// Desktop application configuration
abstract class JvmApplication {
var mainClass: String?
val nativeDistributions: JvmApplicationDistributions
fun nativeDistributions(configure: JvmApplicationDistributions.() -> Unit)
}Cross-platform component libraries providing resources management, UI widgets, and tooling support with consistent APIs across all platforms.
// Resources
@Composable fun stringResource(resource: StringResource): String
@Composable fun painterResource(resource: DrawableResource): Painter
// SplitPane
@Composable fun VerticalSplitPane(
modifier: Modifier = Modifier,
splitPaneState: SplitPaneState = rememberSplitPaneState(),
content: SplitPaneScope.() -> Unit
)
// UI Tooling Preview
@Target(AnnotationTarget.FUNCTION)
annotation class PreviewComplete web development framework with type-safe DOM manipulation, CSS styling, SVG support, and testing utilities for building web applications with Compose.
// DOM Elements
@Composable fun Div(
attrs: AttrBuilderContext<HTMLDivElement>? = null,
content: ContentBuilder<HTMLDivElement>? = null
)
@Composable fun Button(
attrs: AttrBuilderContext<HTMLButtonElement>? = null,
content: ContentBuilder<HTMLButtonElement>? = null
)
// Styling
interface StyleScope {
fun property(propertyName: String, value: StylePropertyValue)
}
// SVG Support
@Composable fun Svg(
viewBox: String? = null,
attrs: AttrBuilderContext<SVGSVGElement>? = null,
content: ContentBuilder<SVGSVGElement>? = null
)// Target formats for desktop distributions
enum class TargetFormat {
AppImage, Deb, Rpm, Dmg, Pkg, Exe, Msi;
val isCompatibleWithCurrentOS: Boolean
}
// Resource environment for localization
class ResourceEnvironment internal constructor(
internal val language: LanguageQualifier,
internal val region: RegionQualifier,
internal val theme: ThemeQualifier,
internal val density: DensityQualifier
)
// CSS units system
interface CSSUnit
interface CSSUnitLength : CSSUnit
val Number.px: CSSLengthValue
val Number.em: CSSLengthValue
val Number.percent: CSSPercentageValue