Agent skill
kotlin-dsl
Kotlin DSL - type-safe builders, Gradle DSL, @DslMarker
Install this agent skill to your Project
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-kotlin/tree/main/skills/kotlin-dsl
SKILL.md
Kotlin DSL Skill
Build type-safe DSLs with Kotlin's language features.
Topics Covered
@DslMarker for Scope Control
@DslMarker
annotation class HtmlDsl
@HtmlDsl
class HTML { fun body(block: Body.() -> Unit) { } }
@HtmlDsl
class Body { fun p(text: String) { } }
// Usage - scoped correctly
html { body { p("Text") } }
Gradle Convention Plugin
// kotlin-library.gradle.kts
plugins { kotlin("jvm"); `java-library` }
kotlin { jvmToolchain(17) }
dependencies {
testImplementation(kotlin("test"))
testImplementation("io.mockk:mockk:1.13.9")
}
tasks.test { useJUnitPlatform() }
Type-Safe Config Builder
@ConfigDsl
class ServerConfig private constructor(val host: String, val port: Int) {
class Builder {
var host = "localhost"
var port = 8080
fun build() = ServerConfig(host, port)
}
}
fun serverConfig(block: ServerConfig.Builder.() -> Unit) =
ServerConfig.Builder().apply(block).build()
// Usage
val config = serverConfig { host = "api.example.com"; port = 443 }
Troubleshooting
| Issue | Resolution |
|---|---|
| Scope pollution | Add @DslMarker annotation |
| Gradle cache stale | Run ./gradlew --stop |
Usage
Skill("kotlin-dsl")
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
kotlin-serialization
kotlinx.serialization - JSON, Protobuf, custom serializers
kotlin-testing
Kotlin testing - JUnit 5, MockK, Kotest, coroutine testing
kotlin-spring
Spring Boot with Kotlin - controllers, services, coroutines
kotlin-di
Dependency Injection - Hilt, Koin, scopes, testing
kotlin-fundamentals
Kotlin language fundamentals - syntax, null safety, data classes, extensions
kotlin-android
Modern Android development - Jetpack, Compose, Architecture Components
Didn't find tool you were looking for?