Ain't Nobody Got kotlin.time for That
I remember this famous scene in the TV show Malcolm in the middle where the father realizes that a lightbulb died and decides to change it, this is pretty much what happened to me as I decided to update some of our dependencies.
These days, I use Kotlin for server side development. I already covered here why I like it and not much has changed since. To go a little deeper into our technology stack, we use Postgresql (with the exposed framework) and describe API specifications with OpenAPI (using Fabrikt for code generation). I’m mentioning those because I had to update them all at once in a massive pull-request impacting around 150 files.
Earlier this week, I ran my script that checks for outdated dependencies in a gradle project and realized there was a bunch of libraries I wanted to update, including the kotlin plugin itself, kotlinx-datetime and exposed.
Updating the version of kotlinx-datetime introduced deprecation warnings: there is no longer need for their Instant and Clock types, since those are now available in Kotlin’s standard library (since version 2.1). Turns out, representing time is a common need, so it made sense to move it there. Unfortunately, updating kotlinx-datetime broke Exposed’s date and time types.
As a result, I switched to a different branch and updated Exposed to 1.0.0-RC-4, which was… a lot of work, but pretty straightforward package changes (org.jetbrains.exposed.sql.Table is now org.jetbrains.exposed.v1.core.Table, etc). It worked until I realized that Exposed depends on… a more recent version of kotlinx-datetime.
After a quick search it looked like I could have used a compatibility version of datetime, but it seemed easier to go for it, merge both branches together and address the errors that popped up.
Lastly, the last task was to upgrade Fabrikt, because the generated code expected to use kotlinx.datetime.Instant and not the never kotlin.time.Instant. After bumping to the latest version and tweaking the code generation command to set the --instant-library option to KOTLIN_TIME_INSTANT, we were back in business.
A pull request that touches around 150 files is way about my comfort threshold, but an extensive suite of tests that covers all the sensitives parts made it a lot more tolerable.