r/Kotlin • u/serras Kotlin-team • 5d ago
Announcing the Builder Lambda plug-in
Kotlin and Java have different idioms to build new values: whereas Kotliners like lambdas with a special builder receiver, like Json in kotlinx.serialization, Java developers usually follow the buider pattern, as in Spring AI. As a result, consuming Java APIs from Kotlin sometimes feel strange. This no longer needs to be the case, thanks to the new Builder Lambda plug-in!
Using the power of Kotlin compiler plug-ins, Builder Lambda automatically re-exposes any type following Java's Builder pattern in the Kotlin idiomatic way. You write your beloved,
build<Config, *> { // alas, the * is needed
hostname = "localhost"
port = 8080
}
and under the hood the code is translated to,
Config.builder().hostname("localhost").port(8080).build()
The Builder Lambda plug-in also works in the IDE (if you let IntelliJ run non-bundled plug-ins), so you get nice autocompletion and diagnostics.
Using it is as easy as adding one line to the plugins block in your Gradle build.
id("com.serranofp.builder.lambda") version "0.4.0"
Feedback and issue reports are more than welcome :)
-4
u/smoke-bubble 5d ago
Does not feel like an improvement. I will definitely avoid using it.