« Jetpack Compose BOM

What is BOM?

The Bill of Materials (BOM) will allow you to manage versions of all your Compose libraries by specifying only the BOM’s version. The BOM has links to the stable versions of the different Compose libraries, in such a way that all the libraries that you’re using in your app are automatically updated to their new versions.

Why use BOM?

What it offers:

  1. BOM helps you to automatically use the latest versions of Compose libraries.
  2. Various Jetpack Compose libraries are moved to independent versioning, so it’s easy to use all of the latest stable versions at the same time.
  3. Using the BOM ensures that the versions of any Compose libraries in your app are compatible.

What it doesn’t:

  1. BOM doesn’t actually add the Compose libraries to your app, you must declare each library as a dependency in the Gradle file.
  2. Compose Compiler library isn’t included in the BOM.

You can still add each dependency version manually. BOM is not mandatory, it provides a way to make library upgrades easy.

How to use BOM?

Add the below Compose BOM dependency in the app/build.gradle file. Make sure you have target SDK version 33. After importing the dependency successfully, declare all your compose libraries in the Gradle dependencies block without versions as shown below.

1plugins {
2 id 'com.android.application'
3 id 'org.jetbrains.kotlin.android'
4}
5
6android {
7 namespace 'com.anish.jetpackcomposebom'
8 compileSdk 33
9
10 defaultConfig {
11 applicationId "com.anish.jetpackcomposebom"
12 minSdk 23
13 targetSdk 33
14 versionCode 1
15 versionName "1.0"
16
17 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 vectorDrawables {
19 useSupportLibrary true
20 }
21 }
22
23 buildTypes {
24 release {
25 minifyEnabled false
26 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 }
28 }
29 compileOptions {
30 sourceCompatibility JavaVersion.VERSION_1_8
31 targetCompatibility JavaVersion.VERSION_1_8
32 }
33 kotlinOptions {
34 jvmTarget = '1.8'
35 }
36 buildFeatures {
37 compose true
38 }
39 composeOptions {
40 kotlinCompilerExtensionVersion '1.1.1'
41 }
42 packagingOptions {
43 resources {
44 excludes += '/META-INF/{AL2.0,LGPL2.1}'
45 }
46 }
47}
48
49dependencies {
50
51 implementation platform('androidx.compose:compose-bom:2022.10.00')
52 implementation "androidx.compose.ui:ui"
53 implementation "androidx.compose.material:material"
54 implementation "androidx.compose.ui:ui-tooling-preview"
55 implementation 'androidx.activity:activity-compose'
56 androidTestImplementation "androidx.compose.ui:ui-test-junit4"
57 debugImplementation "androidx.compose.ui:ui-tooling"
58 debugImplementation "androidx.compose.ui:ui-test-manifest"
59
60 implementation 'androidx.core:core-ktx:1.9.0'
61 implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
62 testImplementation 'junit:junit:4.13.2'
63 androidTestImplementation 'androidx.test.ext:junit:1.1.3'
64 androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
65
66}

How to use a different library version

than the one declared in the BOM? In the dependencies section, on the library dependency import, specify the desired version. For example, if you want to use an alpha version of Material 3, add a dependency implementation 'androidx.compose.material3:material3:1.1.0-alpha01' no matter what version is designated in the BOM, it will consider the declared alpha version of material 3.

That’s it! Now whenever you will update the BOM version from 2022.10.00 to the new version, all other compose library versions will be extracted from that automatically.

For full working code please visit

https://github.com/anishakd4/JetpackComposeBOM