Introducing Jetpack Compose BOM
Complete Guide for understanding Compose Bill of Materials.
Let’s first try to figure out the problem with versioning of compose libraries. Below is sample build.gradle (without BOM) for reference
As we can see that the most compose libraries are having same stable versions and often released with same versions. So, it not a big issue as of now, but issue will start appearing when different libraries will have different stable versions and it will become an overhead to maintain & track versions across multiple libraries. So, to avoid this problem BOM is introduced
BOM (Bills of Material) is the better way to manage android dependencies. Compose BOM lets you manage all of your Compose library versions by specifying only the BOM’s version. The BOM itself has links to the stable versions of the different Compose libraries, in such a way that they work well together. With BOM in your app, you don’t need to add any version to the Compose library dependencies themselves. BOM takes care of it. When you update the BOM version, all the libraries that you’re using are automatically updated to their new versions.
Benefits of using BOM
As of now, we see that the most Compose libraries have common stable versions. So, maintaining common version is still easy. Going forward, Compose libraries will be versioned independently, which means version numbers will start to be incremented at their own pace. The latest stable releases of each library are tested and guaranteed to work nicely together. However, finding the latest stable versions of each library can be difficult, and the BOM helps you to automatically use these latest versions.
Just to add, Compose Compiler library isn’t included in the BOM. The Compose Kotlin compiler extension (androidx.compose.compiler) is not linked to the Compose library versions. Instead, it is linked to versions of the Kotlin compiler plugin and released in a separate cadence from the rest of Compose, so make sure to use a version that is compatible with your version of Kotlin.
Let’s figure out how we can use compose BOM to manage all compose related dependencies.
With BOM
Here, we have only specified the BOM with latest version and skipped respective compose libraries versions.
That’s it! Now you just need to bump BOM version from 2023.03.00 to the latest one, corresponding compose library versions will be picked automatically.
To find out which Compose library versions are mapped to a specific BOM version, check out the BOM to Library version mapping
I hope you will find this post useful & indeed will help you managing dependencies in better way. Feel free to share with others and don’t forget to clap.
Happy Composing