Search code examples
kotlingradleandroid-jetpack-compose

keyword "platform" using compose bom


I’ve been integrating Jetpack BOM into the project, and I’m encountering something that I haven’t found a reasonable explanation for. When adding BOM to the dependencies, the keyword platform is required, as in implementation(platform(bom)). However, I’ve noticed that everything works as expected even without using the platform keyword. I was wondering if someone could clarify whether the platform keyword is necessary and what the potential long-term impact might be if it's omitted


Solution

  • If you omit the platform keyword, Gradle may still resolve the dependencies in a way that works, especially if there are no conflicting versions. However, you lose the explicit guarantee that all the versions are aligned according to the BOM, which can lead to inconsistencies or version conflicts in more complex projects.

    What the platform Keyword Does?

    Platform Dependency Management: The platform keyword indicates that the dependency you are adding (in this case, the BOM) should be treated as a platform dependency. A platform dependency is one that defines a set of compatible versions for a group of artifacts, ensuring that all dependencies in that group are compatible with each other.

    Version Alignment: When you declare a BOM using platform, Gradle ensures that all dependencies managed by that BOM align with the versions specified in it. This prevents version conflicts and helps maintain consistency across dependencies that the BOM manages.

    You can read more about platform and enforcedPlatform from the official doc: https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import