Kotlin: publish the CIO engine apart from the SDK
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 plusktor-client-cio. Ktor finds CIO through its service entry, soBasecampClient { accessToken(...) }works as it did before.- With no
engine/httpClientset, the SDK builds its client through a newdefaultHttpClient(http/DefaultHttpClient.kt). That covers the client and the three OAuth fallbacks. When Ktor's lookup finds no engine, it fails with anIllegalStateExceptionthat names the fix, in place of Ktor's generic message. - Guards:
checkNoBundledEnginefailscheckif any jar on the SDK's runtime classpath registers a Ktor engine.jvmTestNoEnginerunsNoBundledEngineTeston a classpath without CIO.CioEngineTestsends a real request through the engine-less builder withbasecamp-sdk-cioon the classpath.
- I checked that the guard fails: with CIO put back into the SDK's dependencies,
checkNoBundledEnginefails and namesktor-client-cio-jvm-3.6.2.jar. - Also dropped:
ktor-client-content-negotiationandktor-serialization-kotlinx-json. They were declared but never used.
Android: the JVM artifact, no KMP android target
- Nothing in
jvmMainis missing on Android:ConcurrentHashMap,MessageDigest,SecureRandom,javax.crypto.Mac, andjava.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, andBasecampClient { 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 everyio.ktormodule at whichever version wins. Measured earlier with the BOM at 3.6.2: an app'sktor-client-okhttp 3.6.1had been left behindktor-client-core 3.6.2before the BOM, and was aligned after it, andassembleDebugpassed. 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:testand:conformance:testall pass.dependencyInsightresolvesktor-io 3.6.1,kotlinx-serialization-core 1.12.0andkotlinx-io-core 0.9.1, and the POM namesktor-bom/ktor-client-core-jvm3.6.1 andkotlinx-serialization-json-jvm1.12.0. I didn't probe versions below these. - README "Dependency versions" and MIGRATING state the floors. A comment in
libs.versions.tomlmarks them as floors. Note that dependabot's weeklyktor/kotlinxgroups will propose raising them again.
Release plumbing
basecamp-sdk-cioreads its version fromsdk/build.gradle.kts, somake bumpstill writes 11 files and the workflow's tag check is unchanged.release-kotlin.ymlpublishes each of the four publications (root and-jvmof 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:publishhad that gap for its own two publications.release-github.yml's release notes givebasecamp-sdk-cioas the Kotlin install line and point apps with their own engine tobasecamp-sdk.test.yml, the release test job andmake kt-build/kt-testbuild and check both modules.
Notes for reviewers
- The README's OkHttp recipe warns that a
preconfiguredclient'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 onbasecamp-sdk-jvmandktor-client-cio-jvm, andbasecamp-sdk-jvm's carries no engine. In CI,checkNoBundledEnginereads 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 thekaml,snakeyaml-engine-kmpandurlencoder-libit pulls in) came from main'sktor-serialization-kotlinx-json, throughktor-serialization-kotlinx. I read this in Ktor 3.6.2's.modulemetadata. This PR drops that dependency, andktor-client-coredoesn't reachktor-openapi-schema.- On this head,
:basecamp-sdk:dependencies --configuration jvmRuntimeClasspath(the published runtime scope) shows noktor-client-cio,ktor-openapi-schema,kaml,snakeyaml,urlencoderorokhttp(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.