Prosa.kt · Kotlin source generation

Declarative code generation for Kotlin.

Define classes, functions, and expressions in pure Kotlin. Prosa.kt handles the imports, escaping, and formatting.

implementation("com.alexstyl:prosakt:0.1.1")
  • Pure Kotlin
  • Multiplatform
  • MIT licensed

Prosa.kt DSL

ktFile {
ktValue("message") {
initializer { literal("Hello, Kotlin!") }
}
}

Generated Kotlin

val message = "Hello, Kotlin!"

Interactive playground

Try the Prosa.kt DSL.

Choose an example and edit the DSL. The generated Kotlin updates as you type.

Prosa.kt

Generated Kotlin

Loading playground…

Built into the DSL

Focus on what to generate.

Use Kotlin builders to define declarations and expressions. Prosa.kt turns them into source text with imports, escaped literals, and consistent formatting.

Automatic imports

Reference a qualified type or function. Prosa.kt collects, sorts, and deduplicates its imports, and uses qualified names when symbols collide.

Escaped literals

Pass strings and numbers to literal(). Quotes, backslashes, and dollar signs are escaped for the generated Kotlin.

Consistent formatting

Get consistent indentation and automatic line wrapping for structured expressions. Keep generated source readable when reviewing or debugging it.

Getting started

Generate your first
Kotlin file.

Add Prosa.kt to your JVM project or Kotlin Multiplatform source set, then call ktFile to generate source.

Full installation guide

01 Add the dependency

With mavenCentral() configured, add this to your dependencies.

build.gradle.kts
implementation("com.alexstyl:prosakt:0.1.1")

02 Define a file with the DSL

Your generator
import com.alexstyl.prosakt.ktFile
val source = ktFile {
ktValue("message") {
initializer { literal("Hello from Prosa.kt") }
}
}

03 Save the generated source

ktFile returns a string. Save it to a .kt file or pass it to your existing generation pipeline.

Walk through your first Kotlin file

Using Prosa.kt

Common questions.

Which platforms are supported?

All of them. Prosa.kt is written in pure Kotlin and targets JVM, JavaScript, WebAssembly, and Kotlin/Native. Add it to the source set that runs your generator. See the setup for your project.

Does it compile the generated code?

Prosa.kt returns Kotlin source text. Your project handles writing files, registering generated sources, and compilation. The DSL checks structural mistakes, but it does not type-check the generated program.

Can I use my own loops and conditions?

Yes. In your Kotlin project, the builder is ordinary Kotlin: use loops, conditions, and your own functions to drive generation. This browser playground supports a smaller set of builder calls and literal values.

What license does Prosa.kt use?

Prosa.kt is open source under the MIT license. You can use it in personal and commercial projects.Browse the source on GitHub.

Add Prosa.kt to your project

Start generating Kotlin.

Follow the setup guide and generate your first Kotlin file.

Get started