https://kotlinlang.org logo
#getting-started
Title
# getting-started
n

Naveed

02/14/2022, 7:37 PM
Hello, is it currently possible to use Compose for Kotlin Multiplatform to create a common module which can provide Composables to both Kotlin/JVM for Desktop and Kotlin/JS for Web modules? The use case for this would be to create a UI that is consistent across both Desktop and Web without having to recreate UI models separately per platform. I am aware data models can be designed and shared using the architecture stated above but am unsure whether shared composables can be used in the same way. Is it possible to have a module with both jvm + js targets which imports and compiles "org.jetbrains.compose" and creates all the artifacts needed for both JVM and JS modules?
🚫 1
An example error message of this not being allowed to happen (possibly due to me configuring incorrectly):
Copy code
Could not determine the dependencies of task ':web:jsTestPackageJson'.
> Could not resolve all dependencies for configuration ':web:jsTestNpm'.
   > Could not resolve org.jetbrains.compose.foundation:foundation:1.0.1-rc2.
     Required by:
         project :web > project :client-common
      > No matching variant of org.jetbrains.compose.foundation:foundation:1.0.1-rc2 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
          - Variant 'debugApiElements-published' capability org.jetbrains.compose.foundation:foundation:1.0.1-rc2 declares a library:
              - Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
5 Views