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.12k stars 1.17k forks source link

Forced to add compose runtime to jvmMain when using compose + ktor #1568

Closed tom-pratt closed 3 weeks ago

tom-pratt commented 2 years ago

The compileKotlinJvm task fails with:

androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: The Compose Compiler requires the Compose Runtime to be on the class path, but none could be found. The compose compiler plugin you are using (version 1.1.0-beta01) expects a minimum runtime version of 1.0.0.

Unless I add implementation(compose.runtime) to jvmMain.dependencies

But this feels weird since I'm only using compose for the js target.

akurasov commented 2 years ago

Could you share you project? It looks like you also have jvm target in your mpp module.

tom-pratt commented 2 years ago

web.zip

Theres a comment above the line including compose.runtime in jvm. If you comment out that line then the errors occurs.

akurasov commented 2 years ago

The issue is that you have single module project and this module contains both server and Js code. You use Compose plugin in this module, so it is used for all sourceSets. Compose plugin forces usage of Compose Compiler plugin, that checks compose runtime presence. So your build scripts uses Compose for server side.

I would suggest to separate Server and JS code into separate modules.

tom-pratt commented 2 years ago

Ok that makes sense. Although that is the project structure provided in the official sample project for frontend/backend kotlin! Are there any examples using separate modules that you can link to? I suppose you need a third, library module to share the reusable parts between front and backend.

https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform

Artrosis commented 2 years ago

I have a similar problem, I'm adding a spring project to my compose for web project. And I get this error.

akurasov commented 2 years ago

@Artrosis have you split the code into two modules?

Artrosis commented 2 years ago

@akurasov No, I added "implementation(compose.runtime)". I have little experience to do this on my own. I have a Spring project that depends on the build artifacts of a Compose for web project. I would like to have an example application with different Spring and compose for web modules.

akurasov commented 2 years ago

I would like to have an example application with different Spring and compose for web modules.

There is no such at the moment, but probably we should create one.

markusressel commented 1 year ago

Hey there, I am facing the same issue. Any plan on creating a multi-module project example like mentioned above? Is there maybe an existing project on GitHub I can check out? Would love to be able to use JB Compose with a Kotlin backend :nerd_face:

a-blekot commented 1 year ago

I'm also struggling to make it work. I've managed to split demo project into three modules common, server (ktor) and web: https://github.com/a-blekot/jvm-js-fullstack (main branch)

But applications run independently on different ports

server: localhost:8080 (:server:run) web: localhost:8081 (:web:jsBrowserDevelopmentRun)

And I can't register task in the server module to copy webpack output from :web to :server. :web:jsBrowserDevelopmentWebpack Please help))

dima-avdeev-jb commented 1 year ago

@a-blekot Hello! Your project page is not available (https://github.com/a-blekot/jvm-js-fullstack) Can you open your repository or make reproducible sample without security sensitive code?

a-blekot commented 1 year ago

@dima-avdeev-jb Oh, sorry, I didn't notice that it is private. I will update it tomorrow morning cause I'm writing from mobile now)

a-blekot commented 1 year ago

@dima-avdeev-jb done, now it's public https://github.com/a-blekot/jvm-js-fullstack

dima-avdeev-jb commented 1 year ago

@a-blekot Done in this PR: https://github.com/a-blekot/jvm-js-fullstack/pull/1

a-blekot commented 1 year ago

@dima-avdeev-jb Thank you!! It works perfectly now 🥳

mgroth0 commented 9 months ago

Is this issue still open as a suggestion for a feature to be able to enable/disable the compose compiler per source set in Multiplatform? Or should a new issue be opened for that suggestion?

dima-avdeev-jb commented 8 months ago

@mgroth0 You can create a new Issue for your suggestion as a enhancment

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.