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
15.88k stars 1.15k forks source link

IntelliJ code check error when using actual/expect with Compose (Android/Desktop + Web) #2056

Open antoniusnaumann opened 2 years ago

antoniusnaumann commented 2 years ago

I am trying to write a UI component, which can be used from Compose Desktop and Android as well as from Compose Web by using the actual/expect pattern in common code. I then provide two implementations, one for Android & JVM/Desktop, the other for Web.

To achieve this, I added a jsMain and a nonJsMain source set (which desktopMain and androidMain depend on) to the Compose Multiplatform template provided by IntelliJ. However, IntelliJ marks usages of @Composable, etc. as an error in the nonJsMain source set. The demo application which uses the code builds and runs fine.

A workaround is to remove dependsOn(nonJsMain) in the androidMain source set while coding and adding it again when building.

You can find the gradle file here: https://github.com/antoniusnaumann/arc-slider/blob/655309a1ad92eeff6178071988f969a4349ab530/common/build.gradle.kts#L54

Relevant project branch: https://github.com/antoniusnaumann/arc-slider/tree/bugfix/compose-mulitplatform-sourcesets

okushnikov commented 1 month ago

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