Compose - Bill of Materials(BOM)

Compose - Bill of Materials(BOM)

In this article , lets discuss about Bill of Materials

Lets understand why we need BOM , then we will discuss what is BOM

Why BOM?

  • Compose libraries are version independently that is version number are maintained different for each library .

  • For developer , it is difficult to find the latest stable version for each library and add it in dependencies(module level gradle)

    Don't worry BOM is there to save us from this mess

What is BOM?

  • Bill of Materials lets you manage all of our compose library versions by mentioning only the BOM version

  • BOM has link to all the stable version of different compose libraries to work well together

  • When we add BOM in our app , we don't have to mention version for any compose library

  • BOM just ensures that different compose library versions are compatible and it doesn't add any compose library in our app

  • When we update BOM version , all the compose library version mentioned in gradle are automatically updated to their newer/latest version

BOM Usage

    // add BOM
    implementation(platform("androidx.compose:compose-bom:2024.02.01"))
    // add compose library without version number
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    // add a specific version which overrides BOM 
    implementation("androidx.compose.material3:material3:1.2.1")

As we seen in above code , we can observe the following

  1. How to add compose-bom with version number

  2. How to add compose library without version number

  3. How to override desired compose library with our version

BOM supported compose libraries

The following compose libraries and its group is linked to BOM

  • compose.animation

  • compose.foundation

  • compose.material

  • compose.runtime

  • compose.ui

    💡
    Kotlin complier externsion(androidx.compose.compiler) is not linked to BOM , as to make sure we use a version that is compatible to Kotlin version used in our app.

So finally, lets use the Compose - Bill of Materials(recommended not forced to use) and reduce our time to implement the latest versions of compose that work well together .

Please leave your comments to improve.

Happy and Enjoy coding