I'm overriding which Jetpack Compose artifacts are...
# compose-desktop
e
I'm overriding which Jetpack Compose artifacts are resolved in a multiplatform compose project by doing:
Copy code
configurations.configureEach {
  resolutionStrategy {
    eachDependency {
      val isCompiler = requested.group.endsWith("compiler")
      if(requested.group.startsWith("androidx.compose")) {
        if(!isCompiler) {
          useVersion(versionOverride)
        }
      }
    }
  }
}
Now that Jetpack Compose provides a BOM, what would be the best way to do this? Any chance that Jetbrains Compose can expose a property for setting the BOM version to use?
d
We are not planning to use BOM yet. For now, we have a pack of versions with our gradle plugin, like here: https://github.com/JetBrains/compose-jb/blob/master/examples/codeviewer/common/build.gradle.kts#L14
e
I meant to override the android versions. Since Jetbrains Compose writes a version when it redirects to androidx, the BOM doesn't apply.
i.e. the dependency is written as
androidx.compose.ui:ui:<some version>
But to work with the BOM it would need to be
androidx.compose.ui:ui
I was able to get this to work by doing the same thing that Jetbrains Compose does:
Copy code
android {
      dependencies {
        // jetbrains compose plugin rewrites compose dependencies for android to point to androidx
        // if we want to use the compose BOM we need to rewrite the rewritten dependencies to not include a version
        components {
          all {
            val isCompiler = id.group.endsWith("compiler")
            val isCompose = id.group.startsWith("androidx.compose")
            val isBom = id.name == "compose-bom"

            val override = isCompose && !isCompiler && !isBom
            if(override) {
              // copied from Jetbrains Compose RedirectAndroidVariants
              // <https://github.com/JetBrains/compose-jb/blob/612fab6099aa93a6f6d440350c905d948b6f5999/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt#L85>
              listOf(
                "debugApiElements-published",
                "debugRuntimeElements-published",
                "releaseApiElements-published",
                "releaseRuntimeElements-published"
              ).forEach { variantNameToAlter ->
                withVariant(variantNameToAlter) {
                  withDependencies {
                    removeAll { true } // remove androidx artifact with version
                    add("${id.group}:${id.name}") // add androidx artifact without version
                  }
                }
              }
            }
          }
        }
      }
    }
d
Yeah, thanks! We will research a way to simplify using Compose Multiplatform with Jetpack Compose dependencies together.