kotlin-dsl-builders

Design Kotlin DSLs with receivers, nested builders, and @DslMarker scope control.

Updated Apr 8, 2026
One-click install
npx skills add https://github.com/ClankerGuru/opsx --skill kotlin-dsl-builders
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-dsl-builders
Source: https://github.com/ClankerGuru/opsx/tree/main/cli/src/main/resources/content/skills/kotlin-dsl-builders
Command: npx skills add https://github.com/ClankerGuru/opsx --skill kotlin-dsl-builders

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin DSLs provide expressive configuration, but designing them safely and ergonomically requires patterns like receivers, nested builders, and DSL markers to avoid scope leakage and confusion.

Core Features & Use Cases

  • Type-safe DSL blocks using Kotlin's receivers and lambdas with receiver to create expressive configuration APIs.
  • Nested builders with a consistent init pattern and helper utilities to attach built objects.
  • Guidance on scope control via @DslMarker to prevent accidental cross-scope access in complex DSLs.

Quick Start

Create a small Kotlin DSL that configures a sample server using nested blocks.

Frequently Asked Questions about kotlin-dsl-builders

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a type-safe Kotlin DSL for nested configuration blocks?

Design type-safe Kotlin DSLs by applying receivers, lambdas with receiver, and inline functions to create expressive configuration APIs. This approach enables clean, nested builder patterns for library or plugin development.

What is @DslMarker used for in Kotlin DSL builders?

@DslMarker controls scope in Kotlin DSLs to prevent accidental cross-scope access. By applying this annotation, you restrict implicit receivers from outer scopes, eliminating confusion in complex nested builders.

How do I prevent scope leakage when building a Gradle-like Kotlin DSL?

Prevent scope leakage in Gradle-like Kotlin DSLs by using @DslMarker alongside function types with receiver. This combination restricts access to outer builder scopes, ensuring only the intended nested configuration blocks are exposed.

What's the best way to structure nested builders for a Kotlin configuration API?

Structure nested Kotlin builders using a consistent init pattern and helper utilities to attach built objects. Combine this with lambdas with receiver to provide ergonomically safe, expressive configuration blocks for users.

Do I need inline functions to create type-safe builders in Kotlin?

Yes, inline functions are required to create type-safe builders in Kotlin. They reduce performance overhead from lambda allocations while enforcing the receiver-based scope rules essential for clean DSL design.

When should I use lambdas with receiver for Kotlin DSL design?

Use lambdas with receiver for Kotlin DSL design when creating expressive configuration APIs for libraries or plugins. This mechanism allows users to configure nested objects directly within a scoped block, mimicking native Gradle-like syntax.