-
Poko goes multiplatform ⇗
August 9, 2023
Poko is a Kotlin compiler plugin that generates equals, hashCode, and toString functions for annotated classes based on their properties. Inspired by Jake Wharton’s blog post on maintaining compatibility in public APIs, it partially mimics the behavior of Kotlin data classes while leaving out the copy and componentN functions, which are difficult to maintain without breaking API compatibility. Our Paraphrase and Redwood runtimes use Poko. The equals, hashCode, and toString functions are familiar to all JVM developers. But Kotlin generates the exact same set of functions for data classes on all of its multiplatform targets—not just the JVM. It stands to reason that Poko should do the same. And thanks to a slew of recent contributions from Jake, now it does! In addition to the JVM and Android platforms it has supported since its first release 3 years ago, Poko 0.15.0 now supports native and JS targets as well. …
-
How Poko works
December 1, 2021
The Kotlin compiler’s job is to convert source code into byte code. Compiler plugins like Poko are able to intercept a representation of the source code during compilation and affect the produced byte code. To this end, Poko’s purpose is fairly straightforward: for any source class with the @Poko annotation, produce byte code that uses that class’s primary constructor properties in three overridden functions. To complicate things, Kotlin added a new compiler backend in 1.4, and made that new backend the default in 1.5. So depending on the mode in which the compiler runs, the byte code output is completely different: either classic JVM byte code or IR byte code. Poko supports both, effectively meaning this plugin’s core functions must be written twice. …
-
Flexible configuration with Deferred Resources ⇗
June 21, 2021
Our feature libraries, which include UI, have a number of varying requirements regarding configuration by our customers. (My colleague Hari wrote about one such library’s requirements here.) Resources (text, colors, images, etc.) are a common type of configuration, and can be defined in various ways—typically in code, resources, or theme attributes. We created Deferred Resources to support such configurations, and with it our customers can consistently declare configuration properties from any of these common sources: …
-
Monitoring binary compatibility on a pre-stable project
April 28, 2020
The open-source Kotlin binary compatibility validator is a great tool. When added to a project, it fails the build on any change to the public API surface. If a public API change is intentional, ./gradlew apiDump fixes the build by updating the summary of the public API in source control. If you maintain a library that is consumed as a compiled binary, it is wise to use some form of binary compatibility validation, and this is the easiest such tool I know of. It takes maybe 3 minutes to add it to a project, and the public API summary it produces is easy for a developer to read. …