JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.25k stars 1.18k forks source link

Could not resolve all dependencies for configuration ':shared:jsCompileClasspath'. > Could not resolve io.realm.kotlin:library-base:1.11.0. Required by: project :shared #3740

Closed ismai117 closed 1 year ago

ismai117 commented 1 year ago

I'm using realm in my kmp app, I know that realm isn't compatible with web yet so I want to run web without realm library but I keep on receiving an error


Could not resolve all dependencies for configuration ':shared:jsCompileClasspath'.
> Could not resolve io.realm.kotlin:library-base:1.11.0.
  Required by:
      project :shared
   > No matching variant of io.realm.kotlin:library-base:1.11.0 was found. The consumer was configured to find a library for use during 'kotlin-api', 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 'iosArm64ApiElements-published' capability io.realm.kotlin:library-base:1.11.0 declares a library for use during 'kotlin-api':
           - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed 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')
       - Variant 'iosArm64MetadataElements-published' capability io.realm.kotlin:library-base:1.11.0 declares a library:
           - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed a component for use during 'kotlin-api', 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')
       - Variant 'iosArm64SourcesElements-published' capability io.realm.kotlin:library-base:1.11.0:
           - Incompatible because this component declares documentation for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed a library for use during 'kotlin-api', 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')
       - Variant 'iosSimulatorArm64ApiElements-published' capability io.realm.kotlin:library-base:1.11.0 declares a library for use during 'kotlin-api':
           - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed 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')
       - Variant 'iosSimulatorArm64MetadataElements-published' capability io.realm.kotlin:library-base:1.11.0 declares a library:
           - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
           - Other compatible attributes:
ismai117 commented 1 year ago

I tried this solution but its not working val jsMain by getting { dependsOn(commonMain) dependencies { implementation(compose.html.core) implementation("io.realm.kotlin:library-base:$realmVersion") { exclude(group = "io.realm.kotlin", module = "library-base") } implementation("io.realm.kotlin:library-sync:$realmVersion") { exclude(group = "io.realm.kotlin", module = "library-sync") } } }

pablichjenkov commented 1 year ago

It seems that Realm.db doesn't support JS target.

ismai117 commented 1 year ago

thanks @pablichjenkov , it looks this js(IR) { browser() } is causing the issue. can I exclude realm inside js(IR) { exclude ("io.realm.kotlin:library-base:1.11.0") } ?

ismai117 commented 1 year ago

js(IR) { browser() configurations { all { exclude(group = "io.realm.kotlin", module = "library-base") exclude(group = "io.realm.kotlin", module = "library-sync") } } }. I did this, it removed the error but now its removed realm for iOS, android and desktop

pablichjenkov commented 1 year ago

I don't think an exclusion rule will apply here. It would be a nice feature request but normally gradle tries to resolve all dependencies first then apply the exclusion rules. In any case the exclusion rule should be applied in the JS target only, your code above is basically removing it from everywhere.

You should create an intermediate target named onlyMobile, it will have your only mobile dependencies, then make Android and iOS target depend on onlyMobile. Your realmdb dependency will be in onlyMobile not in common. I could provide some code snippet but I am on my phone atm.

ismai117 commented 1 year ago

yeah that would be a great feature, also I'm using realm for desktop so can you show a snippet when you're free please. thanks!

pablichjenkov commented 1 year ago

Check this project: https://github.com/pablichjenkov/kmp-amadeus-api/blob/d4b296ccfd6416e79125143e24290a8c216a93c8/amadeus-api/build.gradle.kts#L153

eymar commented 1 year ago

Thank you @pablichjenkov for helping with this question! :)

@ismai117 Feel free to add more questions if needed.

To summarize: If some libs don't support a particular target (k/js in this case), then that target shouldn't have it as a dependency. As @pablichjenkov has shown, it can be done by adding extra source sets to for supported/unsupported targets.

ismai117 commented 1 year ago

that's all sorted on my side now, thanks for the help!!

okushnikov commented 4 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.