skills/coding/coding-kotlin/SKILL.md
Kotlin: coroutines, data classes, sealed classes, extension functions, Gradle, KMM multiplatform
npx skillsauth add alphaonedev/openclaw-graph coding-kotlinInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill equips the AI to generate, debug, and optimize Kotlin code, focusing on coroutines for async operations, data classes for immutable data handling, sealed classes for type-safe hierarchies, extension functions for reusable code, Gradle for project builds, and KMM for multiplatform development.
Use this skill for Android app development requiring async tasks (e.g., network calls), data modeling in APIs, or cross-platform projects with shared logic. Apply it when performance matters, like using coroutines to avoid blocking threads, or when setting up Gradle for dependency management in KMM setups.
kotlinx.coroutines for non-blocking I/O.data class User(val name: String, val id: Int).sealed class Result { data class Success(val data: String) : Result() }.fun String.reverse() = this.reversed().To accomplish tasks, always import necessary packages first (e.g., import kotlinx.coroutines.*). For async operations, wrap code in a coroutine scope like runBlocking { } and use launch for fire-and-forget or async for awaited results. When modeling data, use data classes for POJOs and sealed classes for state machines. For Gradle tasks, run commands from the project root and pass flags like --info for debugging. In KMM projects, structure code into shared and platform-specific modules, then link via Gradle configurations. Always check for nullability with ? to prevent crashes.
gradle build --stacktrace to compile and debug; use gradle assembleDebug for Android builds; in KMM, add dependencies in build.gradle.kts like implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4").launch { delay(1000L); println("Task completed") } for delayed execution; or val deferred = async { someFunction() }; deferred.await() for concurrent tasks.data class Person(val name: String); val p = Person("John"); println(p.copy(name = "Jane")) to create copies with modifications.when (result) { is Result.Success -> process(data); is Result.Error -> handleError() } for exhaustive checking.fun Int.isEven() = this % 2 == 0; val num = 4; println(num.isEven()) to extend built-ins.kotlin { android { compilations.all { kotlinOptions.jvmTarget = "1.8" } } ios { binaries { framework() } } } for multiplatform configuration.HttpClient().get("https://api.example.com/data") with auth via env var like $KOTLIN_API_KEY in headers.Integrate this skill by ensuring the environment has Kotlin SDK installed (e.g., via SDKMAN: sdk install kotlin). For Android, add Kotlin plugins in build.gradle: plugins { id("org.jetbrains.kotlin.android") } and set minSdk to 21 for coroutines. In KMM projects, link shared modules with expect fun platformFunction() in common code and actual fun platformFunction() = ... in platform-specific files. Use environment variables for secrets, like setting $GRADLE_API_KEY for repository access in gradle.properties: apiKey=$GRADLE_API_KEY. Test integrations with ./gradlew test and handle platform differences by checking OS via System.getProperty("os.name").
Always use structured error handling in coroutines: wrap code in try { launch { riskyOperation() } } catch (e: CancellationException) { log("Coroutine cancelled") } finally { cleanup() }. For data classes, validate inputs at construction: e.g., data class User(val name: String) { init { require(name.isNotBlank()) { "Name cannot be blank" } } }. In sealed classes, ensure all subclasses are handled in when expressions to avoid UnreachableCode errors. For Gradle, parse output with --stacktrace and check for common issues like dependency conflicts by running gradle dependencies. In KMM, handle platform-specific errors with expect class PlatformException() { actual constructor() } and catch in common code.
Example: Asynchronous network call with coroutines
Import coroutines and launch a scope: import kotlinx.coroutines.*; suspend fun fetchData() = "Data"; fun main() = runBlocking { val result = async { fetchData() }.await(); println(result) }. This fetches data without blocking the main thread.
Example: Modeling API response with sealed classes and data classes
Define structures: sealed class ApiResult { data class Success(val data: String) : ApiResult(); data class Error(val message: String) : ApiResult() }; fun process(result: ApiResult) = when (result) { is Success -> println(result.data); is Error -> println(result.message) }. Use this to handle responses safely in KMM shared code.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui