Why are data classes from my library module treated as unstable by the Compose compiler?
0 reputation · 19 Jan 2022, 07:49 UTC
I have a multi-module Android project using Jetpack Compose (compiler 1.5.x, Kotlin 1.9). UI state is modeled as plain Kotlin data classes in a shared :core:model module, and composables in :feature modules consume them. The generated Compose compiler reports show these data classes classified as unstable, even though they contain only val properties of primitive and String types. Identical classes declared inside the app module are inferred as stable.
My understanding is that stability inference does not cross module boundaries for non-annotated types, so consumers must treat external classes as unstable. This forces recomposition of every composable that takes these models as parameters, and I would rather not annotate shared model classes with Compose-specific annotations like @Stable or @Immutable, since the model module has no Compose dependency.
Is there a supported way to make the compiler treat classes from another module as stable without adding a Compose dependency to that module — for example, a stability configuration file, and is that mechanism officially documented and safe to rely on across compiler upgrades?
Alternatively, is wrapping the models in stable types at the feature-module boundary the recommended pattern, and does it carry meaningful runtime or maintenance overhead compared to annotating the models directly?