kotlin-dsl

Kotlin DSL - type-safe builders, Gradle DSL, @DslMarker

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "kotlin-dsl" with this command: npx skills add pluginagentmarketplace/custom-plugin-kotlin/pluginagentmarketplace-custom-plugin-kotlin-kotlin-dsl

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

IssueResolution
Scope pollutionAdd @DslMarker annotation
Gradle cache staleRun ./gradlew --stop

Usage

Skill("kotlin-dsl")

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

kotlin-compose

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

kotlin-android

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

kotlin-testing

No summary provided by upstream source.

Repository SourceNeeds Review