Kotlin: publish the CIO engine apart from the SDK

Merged
JE
1d ago
+423-42

The Kotlin SDK stops bundling Ktor's CIO engine. com.basecamp:basecamp-sdk now depends on the Ktor client API only, and CIO moves to a new artifact, com.basecamp:basecamp-sdk-cio, published at the same version. An Android app on OkHttp no longer carries CIO as a second HTTP stack. With no engine named, Ktor picks the highest-priority engine on the classpath, and CIO ranks lowest (CIOEngineContainer.priority = 0.0 at 3.6.2).

Breaking for JVM callers that relied on the bundled engine: they add basecamp-sdk-cio, and MIGRATING.md says how. Code that sets engine or httpClient is unaffected.

Engine

  • basecamp-sdk-cio (kotlin/cio) has no code. It is the SDK plus ktor-client-cio. Ktor finds CIO through its service entry, so BasecampClient { accessToken(...) } works as it did before.
  • With no engine/httpClient set, the SDK builds its client through a new defaultHttpClient (http/DefaultHttpClient.kt). That covers the client and the three OAuth fallbacks. When Ktor's lookup finds no engine, it fails with an IllegalStateException that names the fix, in place of Ktor's generic message.
  • Guards:
    • checkNoBundledEngine fails check if any jar on the SDK's runtime classpath registers a Ktor engine.
    • jvmTestNoEngine runs NoBundledEngineTest on a classpath without CIO.
    • CioEngineTest sends a real request through the engine-less builder with basecamp-sdk-cio on the classpath.
  • I checked that the guard fails: with CIO put back into the SDK's dependencies, checkNoBundledEngine fails and names ktor-client-cio-jvm-3.6.2.jar.
  • Also dropped: ktor-client-content-negotiation and ktor-serialization-kotlinx-json. They were declared but never used.

Android: the JVM artifact, no KMP android target

  • Nothing in jvmMain is missing on Android: ConcurrentHashMap, MessageDigest, SecureRandom, javax.crypto.Mac, and java.util.Base64 (generatePkce, API 26; core-android's minSdk is 28).
  • Bytecode is now pinned to Java 17 (jvmTarget, release), which is core-android's default. It used to follow the building JDK: CI's 17 produced class version 61, but a JDK 21 build would have produced 65.
  • Proof: a scratch Android app consumed the published JVM artifacts from a file repository and passed assembleDebug (Kotlin compile and D8 dex). It used AGP 9.5.0, compileSdk 37, minSdk 28, Kotlin 2.4.21, and BasecampClient { engine = OkHttp.create() }.
  • So a KMP android target, with its AGP, google() and Android SDK in CI, isn't needed.

Version alignment: published floors

  • The SDK now asks for Ktor 3.6.1 and kotlinx.serialization 1.12.0, core-android's versions. Before this it asked for 3.6.2 and 1.13.0, which moved such an app up by Gradle's conflict resolution. An app at or above the floor keeps its own versions.
  • api(platform(io.ktor:ktor-bom)), also at 3.6.1, still aligns every io.ktor module at whichever version wins. Measured earlier with the BOM at 3.6.2: an app's ktor-client-okhttp 3.6.1 had been left behind ktor-client-core 3.6.2 before the BOM, and was aligned after it, and assembleDebug passed. The BOM constrains with plain "requires", so it never raises past what the build asks for.
  • Proof at the floor (a30d639): :basecamp-sdk:check (797 jvmTest, 5 jvmTestNoEngine), :basecamp-sdk-cio:check, :generator:test and :conformance:test all pass. dependencyInsight resolves ktor-io 3.6.1, kotlinx-serialization-core 1.12.0 and kotlinx-io-core 0.9.1, and the POM names ktor-bom/ktor-client-core-jvm 3.6.1 and kotlinx-serialization-json-jvm 1.12.0. I didn't probe versions below these.
  • README "Dependency versions" and MIGRATING state the floors. A comment in libs.versions.toml marks them as floors. Note that dependabot's weekly ktor/kotlinx groups will propose raising them again.

Release plumbing

  • basecamp-sdk-cio reads its version from sdk/build.gradle.kts, so make bump still writes 11 files and the workflow's tag check is unchanged.
  • release-kotlin.yml publishes each of the four publications (root and -jvm of each module, the SDK first) in its own Gradle invocation, with its own 409 handling. A re-run after a partial publish can't let one publication's 409 stand in for another that is missing. Before this, :basecamp-sdk:publish had that gap for its own two publications.
  • release-github.yml's release notes give basecamp-sdk-cio as the Kotlin install line and point apps with their own engine to basecamp-sdk.
  • test.yml, the release test job and make kt-build/kt-test build and check both modules.

Notes for reviewers

  • The README's OkHttp recipe warns that a preconfigured client's interceptors run on every request the SDK sends, a download's hop to a signed storage URL included. So an interceptor that adds the app's own credential everywhere would send it there.
  • The Java 17 pin changes no published bytes. CI builds on JDK 17, and 0.40.0's classes are already version 61. The pin only stops a different JDK from changing that.
  • The published POMs and Gradle metadata were checked by hand, through the consumer above, and not by a CI gate. basecamp-sdk-cio-jvm's POM depends on basecamp-sdk-jvm and ktor-client-cio-jvm, and basecamp-sdk-jvm's carries no engine. In CI, checkNoBundledEngine reads the same dependency declarations the publication is built from.

Not here

  • Date types: lane J's "Give Kotlin its own CalendarDate and drop kotlinx-datetime" (branch J-kotlin, 3476cf5d, for #1140) handles them. This PR doesn't touch them.
  • Divergence from hey-sdk: it still bundles CIO in jvmMain. The same split would apply there.

Dependency footprint (follow-up to the Android dependency diff)

  • Baseline, measured on main's SDK in an Android R8 release build with an app executor: the SDK costs +377 KB APK (+1.28%) and +366 KB DEX (+1.64%). io.ktor.client.engine.cio.* kept 23 classes, because the SDK linked CIO as the default engine. kotlinx.datetime.* kept 86 classes; lane J's Kotlin dates change removes them.
  • ktor-openapi-schema (and the kaml, snakeyaml-engine-kmp and urlencoder-lib it pulls in) came from main's ktor-serialization-kotlinx-json, through ktor-serialization-kotlinx. I read this in Ktor 3.6.2's .module metadata. This PR drops that dependency, and ktor-client-core doesn't reach ktor-openapi-schema.
  • On this head, :basecamp-sdk:dependencies --configuration jvmRuntimeClasspath (the published runtime scope) shows no ktor-client-cio, ktor-openapi-schema, kaml, snakeyaml, urlencoder or okhttp (0 lines match). An app that supplies its own engine therefore has no CIO classes left for R8 to keep. The after-split APK/DEX numbers are lane L's to measure on this branch.
  • Minimum versions: Ktor 3.6.1 and kotlinx.serialization 1.12.0, tested as above. The SDK uses kotlinx-io only through Ktor (0.9.1 under Ktor 3.6.1).
  • Alignment strategy: published floors plus the Ktor BOM at the floor; see Version alignment above.
  • sdk-validation/android: the only build change Android required there was kotlinx-datetime, which is lane J's.