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.95k stars 1.16k forks source link

Web compose: cannot resolve mavenCentral imports #947

Closed lynnjo closed 3 years ago

lynnjo commented 3 years ago

I am using IntelliJ IDEA 2021.1.2 (Ultimate Edition)

When using jetpack compose desktop from IntelliJ, I can include mavenCentral() as a repository, and in the dependencies section of the build.gradle.kts file, include imports of projects as shown below. Functions referenced from the included repositories/dependencies are resolved when the project is built.

repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") }

dependencies { implementation(kotlin("stdlib-common")) implementation(compose.desktop.currentOs) implementation(compose.runtime) implementation(compose.desktop.common) implementation("net.maizegenetics:tassel6:6.0.1") implementation("com.google.guava:guava:29.0-jre") }

However, when I try to do the same for an IntelliJ jetpack Web compose project, the gradle build finishes without error, but the files will not compile as they are unable to resolve the dependencies. Note the "External Libraries" tab in the Intellij window shows the requested libraries have been imported.

repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") }

kotlin { js(IR) { browser() binaries.executable() } sourceSets { val jsMain by getting { dependencies { implementation(compose.web.core) implementation(compose.runtime) implementation("net.maizegenetics:tassel6:6.0.1") implementation("com.google.guava:guava:29.0-jre") } } } }

Below is a very simple file Main.kt file from WEB compose project where "Multimap" and "HashMultimap" are not resolved from com.google.common.collect.* and "BuilderFromHaplotypeVCF" is not resolved from net.maizegenetics.dna.factor.io.BuilderFromHaplotypeVCF. These same lines work when put into a jetpack desktop compose project.

Does jetpack compose web not support maven dependencies?

-------------- File------------ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue import org.jetbrains.compose.web.css.padding import org.jetbrains.compose.web.css.px import org.jetbrains.compose.web.dom.Button import org.jetbrains.compose.web.dom.Div import org.jetbrains.compose.web.dom.Span import org.jetbrains.compose.web.dom.Text import org.jetbrains.compose.web.renderComposable import net.maizegenetics.dna.factor.io.BuilderFromHaplotypeVCF import com.google.common.collect.* fun main() { var count: Int by mutableStateOf(0)

// These 3 lines put here to try to get TASSEL6 imports to work
// And the Multimap is from com.google.common.collect.*  - added
// to test if ANYTHING can be resolved from a mavenCentral import 
// Both are resolved in compose desktop, but neither are resolved in this compose web project

val set1Map: Multimap<Int,IntRange> = HashMultimap.create()
val filename = "/Users/lcj34/notes_files/phg_2018/jetpack_compose/nam_merged_haplotypes_chr10.vcf.gz"
val featureTable = BuilderFromHaplotypeVCF().read(filename)

renderComposable(rootElementId = "root") {
    Div({ style { padding(25.px) } }) {
        Button(attrs = {
            onClick { count -= 1 }
        }) {
            Text("-")
        }

        Span({style { padding(15.px) }}) {
            Text("$count")
        }

        Button({
            onClick { count += 1 }
        }) {
            Text("+")
        }
    }
}

}

Thanks, Lynn

hfhbd commented 3 years ago

It has nothing to do with MavenCentral. Many libraries are published to MavenCentral, even some required by Compose (Web) itself.

You are trying to add a JVM libary net.maizegenetics.dna to a JS target Compose Web.

lynnjo commented 3 years ago

To clarify: That is my question. Adding this library works for jetpack compose desktop but not for jetpack compose web. is this expected? Are JVM libraries not supported by jetpack compose web ? Can you explain why?

hfhbd commented 3 years ago

Compose Web is a web library targeting your browser, which has fundamental different use cases, requirements, limitations and APIs. Beside executing, compiling JVM sources to a JS target is not supported by the Kotlin compiler at all. You don't have a JVM inside your browser. Instead, Kotlin code in the JS source set is compiled to plain JavaScript. For example, how do you read your file val filename = "/Users/lcj34/notes_files/phg_2018/jetpack_compose/nam_merged_haplotypes_chr10.vcf.gz" from your browser? Fortunately, JavaScript has no access to your file system. Otherwise every website could read your local data...

https://kotlinlang.org/docs/js-overview.html

lynnjo commented 3 years ago

Thank you for the explanation.

akurasov commented 3 years ago

@lynnjo do you have any other questions here?

lynnjo commented 3 years ago

No other questions right now - you can close this issue. Thanks for the information.

okushnikov commented 3 weeks ago

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