A Gradle plugin that generates a clean DSL surface for your Kotlin modules. Annotate the classes and functions you want to expose with @Export and kexport generates a single Dsl.kt file containing type aliases and delegating wrapper functions — keeping internal implementation details hidden behind a stable public API.
Add next to your build.gradle.kt:
plugins {
kotlin("jvm")
id("com.happix.kexport") //TODO add latest published version
}
kexport {
packageToScan = "com.example.mymodule" // scan this package and all sub-packages
outputPackage = "com.example.mymodule.dsl" // same as default
}Annotate your classes with @Export
import com.happix.kexport.Export
@Export
data class User(...) { ... }
@Export(alias = "Item")
data class ProductItem(...) {...}
@Export
fun greet(name: String)
All exports are collected into a single generated file in a package of your choosing. Your consumers can then import than everything that your lib exposes using:
import com.example.mymodule.dsl.*
val user: User = User(id = 1, name = "Alice", email = "alice@example.com")
val item: Item = Item(id = 42, name = "Widget", price = 9.99)
println(greet("World"))At build time, kexport uses KSP to generate next file:
// Auto-generated by kexport — do not edit manually.
package com.example.mymodule.dsl
typealias User = com.example.mymodule.models.User
typealias Item = com.example.mymodule.models.subpackage.Product
inline fun greet(name: String): String = com.example.mymodule.models.greet(name)Consumers import from the output package and are completely decoupled from the internal structure:
- Every exported symbol must have a unique export name within the scanned packages — including across classes and functions. Two symbols that resolve to the same name (either by their own simple name or via
alias) will cause a build error. - For sealed classes, every direct subclass must also be annotated with
@Export. The build fails with a descriptive error if any subclass is missing the annotation.
| Property | Required | Default | Description |
|---|---|---|---|
packageToScan |
Yes | — | Package prefix to scan. All sub-packages are included. |
outputPackage |
No | {packageToScan}.dsl |
Package for the generated file. |
outputFileName |
No | Dsl.kt |
Name of the generated file. |
- Support for varargs
- Support for
Interfaces - Support for
sealedclasses - Allow to use your own KSP processor version
- Add support for using
kaptnext to existingkspsupport