Installation
Supporting a single platform
Doodle apps are built using Gradle like other Kotlin apps. These apps can be developed to target multiple platforms, with various build configurations depending on the mix of platforms supported.
The following shows how to configure your app for various targets.
- Browser (JavaScript)
- Browser (WasmJs)
- Desktop (JVM)
You can set up an app that runs in the Browser using JavaScript with the following build script.
build.gradle.kts
plugins {
id ("org.jetbrains.kotlin.multiplatform") version "2.1.10"
}
version = "1.0.0"
group = "com.my.cool.app"
repositories {
mavenCentral()
}
kotlin {
js {
browser {
binaries.executable()
}
}
val doodleVersion = "0.11.1" // <--- Latest Doodle version
dependencies {
implementation ("io.nacular.doodle:browser:$doodleVersion")
// Optional
// implementation ("io.nacular.doodle:controls:$doodleVersion" )
// implementation ("io.nacular.doodle:animation:$doodleVersion")
// implementation ("io.nacular.doodle:themes:$doodleVersion" )
}
}
Learn more about Kotlin for Javascript.
WasmJs apps run in the Browser and are configured as follows.
build.gradle.kts
plugins {
id ("org.jetbrains.kotlin.multiplatform") version "2.1.10"
}
version = "1.0.0"
group = "com.my.cool.app"
repositories {
mavenCentral()
}
kotlin {
wasmJs {
browser {
binaries.executable()
}
}
val doodleVersion = "0.11.1" // <--- Latest Doodle version
dependencies {
implementation ("io.nacular.doodle:browser:$doodleVersion")
// Optional
// implementation ("io.nacular.doodle:controls:$doodleVersion" )
// implementation ("io.nacular.doodle:animation:$doodleVersion")
// implementation ("io.nacular.doodle:themes:$doodleVersion" )
}
}
Learn more about Kotlin for WebAssembly.
You can set up a pure JVM app that runs on Desktop with the following build scripts.
build.gradle.kts
plugins {
id ("org.jetbrains.kotlin.jvm") version "2.1.10"
application
}
version = "1.0.0"
group = "com.my.cool.app"
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
kotlin {
compilerOptions {
jvmTarget.set(JVM_11) // JVM 11 is needed for Desktop
}
withJava()
val doodleVersion = "0.11.1" // <--- Latest Doodle version
dependencies {
// helper to derive OS/architecture pair
when (osTarget()) {
"macos-x64" -> implementation("io.nacular.doodle:desktop-jvm-macos-x64:$doodleVersion" )
"macos-arm64" -> implementation("io.nacular.doodle:desktop-jvm-macos-arm64:$doodleVersion" )
"linux-x64" -> implementation("io.nacular.doodle:desktop-jvm-linux-x64:$doodleVersion" )
"linux-arm64" -> implementation("io.nacular.doodle:desktop-jvm-linux-arm64:$doodleVersion" )
"windows-x64" -> implementation("io.nacular.doodle:desktop-jvm-windows-x64:$doodleVersion" )
"windows-arm64" -> implementation("io.nacular.doodle:desktop-jvm-windows-arm64:$doodleVersion")
}
// Optional
// implementation ("io.nacular.doodle:controls:$doodleVersion" )
// implementation ("io.nacular.doodle:animation:$doodleVersion")
// implementation ("io.nacular.doodle:themes:$doodleVersion" )
}
// could be moved to buildSrc, but kept here for clarity
fun osTarget(): String {
val osName = System.getProperty("os.name")
val targetOs = when {
osName == "Mac OS X" -> "macos"
osName.startsWith("Win" ) -> "windows"
osName.startsWith("Linux") -> "linux"
else -> error("Unsupported OS: $osName")
}
val targetArch = when (val osArch = System.getProperty("os.arch")) {
"x86_64", "amd64" -> "x64"
"aarch64" -> "arm64"
else -> error("Unsupported arch: $osArch")
}
return "${targetOs}-${targetArch}"
}
}
application {
mainClass.set("YOUR_CLASS")
}
Learn more about Kotlin for the JVM.
Target multiple platforms
Doodle is a set of Kotlin Multi-platform libraries. Which means you can create an MPP for your app as well. The advantage of this is that you can write your app entirely (except for main
) in common
code and make it available on both Web (JS, WasmJS) and Desktop (JVM). The following shows how to create such an app.
App launch code is the only portion that needs to be in jsMain
or jvmMain
.
build.gradle.kts
plugins {
id ("org.jetbrains.kotlin.multiplatform") version "2.1.10"
application
}
version = "1.0.0"
group = "com.my.cool.app"
repositories {
mavenCentral()
maven {
url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
kotlin {
js {
browser {
binaries.executable()
}
}
wasmJs {
browser {
binaries.executable()
}
}
jvm {
compilerOptions {
jvmTarget.set(JVM_11) // JVM 11 is needed for Desktop
}
withJava()
}
val doodleVersion = "0.11.1" // <--- Latest Doodle version
sourceSets {
val commonMain by getting {
dependencies {
// Optional
// implementation ("io.nacular.doodle:controls:$doodleVersion" )
// implementation ("io.nacular.doodle:animation:$doodleVersion")
// implementation ("io.nacular.doodle:themes:$doodleVersion" )
}
}
val jsMain.dependencies {
implementation ("io.nacular.doodle:browser:$doodleVersion")
}
jvmMain.dependencies {
// helper to derive OS/architecture pair
when (osTarget()) {
"macos-x64" -> implementation("io.nacular.doodle:desktop-jvm-macos-x64:$doodleVersion" )
"macos-arm64" -> implementation("io.nacular.doodle:desktop-jvm-macos-arm64:$doodleVersion" )
"linux-x64" -> implementation("io.nacular.doodle:desktop-jvm-linux-x64:$doodleVersion" )
"linux-arm64" -> implementation("io.nacular.doodle:desktop-jvm-linux-arm64:$doodleVersion" )
"windows-x64" -> implementation("io.nacular.doodle:desktop-jvm-windows-x64:$doodleVersion" )
"windows-arm64" -> implementation("io.nacular.doodle:desktop-jvm-windows-arm64:$doodleVersion")
}
}
// could be moved to buildSrc, but kept here for clarity
fun osTarget(): String {
val osName = System.getProperty("os.name")
val targetOs = when {
osName == "Mac OS X" -> "macos"
osName.startsWith("Win" ) -> "windows"
osName.startsWith("Linux") -> "linux"
else -> error("Unsupported OS: $osName")
}
val targetArch = when (val osArch = System.getProperty("os.arch")) {
"x86_64", "amd64" -> "x64"
"aarch64" -> "arm64"
else -> error("Unsupported arch: $osArch")
}
return "${targetOs}-${targetArch}"
}
}
}
application {
mainClass.set("YOUR_CLASS")
}