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

Default configuration for Compose Desktop Application is disabled: multiple Kotlin JVM targets definitions are detected. Specify, which target to use by using `compose.desktop.application.from(kotlinMppTarget)` #1727

Open LarsArtmann opened 2 years ago

LarsArtmann commented 2 years ago

``I know the documentation says two java modules are not possible but it would really help me if it is and my testing doesn't suggest it is the case, anyway I got this error message that I couldn't find a fix for:

"w: Default configuration for Compose Desktop Application is disabled: multiple Kotlin JVM targets definitions are detected. Specify, which target to use by using compose.desktop.application.from(kotlinMppTarget)"

My build.gradle.kts

import org.jetbrains.compose.compose
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose") version "1.1.0-alpha1-dev550"
    id("com.android.library")
    kotlin("plugin.serialization") version "1.6.10"
}

group = "lars.software"
version = "1.0.0"

lateinit var srcForDesktop: KotlinSourceSet

@Suppress("UNUSED_VARIABLE")
kotlin {
    android()
    jvm("desktop") {
        compilations.all {
            kotlinOptions.jvmTarget = "11"
        }
    }
    //mingwX64("windows")
    jvm("eventProcessor") {
        compilations.all {
            kotlinOptions.jvmTarget = "11"
        }
    }
//    js {
//        browser {
//        }
//    }
    val ktorVersion = "1.6.7"
    sourceSets {
        val commonData by creating {
            dependencies {
                //ktor
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
                implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
                //kotlinx.serialization
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
                //kotlinx-datetime
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
            }
        }
        val eventProcessorMain by getting {
            dependsOn(commonData)
        }
        val commonUI: KotlinSourceSet by creating {
            dependsOn(commonData)
            dependencies {
                api(compose.runtime)
                api(compose.foundation)
                api(compose.material)
            }
        }
        srcForDesktop = commonUI
        val androidMain by getting {
            dependsOn(commonUI)
            dependencies {

                //Ktor
                implementation("io.ktor:ktor-client-android:$ktorVersion")

                api("androidx.appcompat:appcompat:1.4.1")
                api("androidx.core:core-ktx:1.7.0")

                implementation("com.google.firebase:firebase-common-ktx:20.0.0")
                implementation("com.google.firebase:firebase-firestore-ktx:24.0.0")
            }
        }
        val desktopMain by getting {
            dependsOn(commonUI)
            dependencies {

                //Ktor
                implementation("io.ktor:ktor-client-cio:$ktorVersion")

                implementation(compose.preview)
                implementation(compose.desktop.currentOs)
            }
        }
//        val windowsMain by getting {
//            dependsOn(desktopMain)
//        }
    }
}

android {
    compileSdk = 31
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 31
        targetSdk = 31
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

compose.desktop {
    application {
        mainClass = "$group.desktop.MainKt"
        nativeDistributions {
            targetFormats(
                org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg,
                org.jetbrains.compose.desktop.application.dsl.TargetFormat.Msi,
                org.jetbrains.compose.desktop.application.dsl.TargetFormat.Deb
            )
            packageName = "jvm"
            packageVersion = version.toString()
        }
    }
}
akurasov commented 2 years ago

It looks like a Kotlin plugin issue, not a Compose one. Why don't you just use two separate JVM gradle modules?

LarsArtmann commented 2 years ago

One is for the data model I want to reuse in the backend the other one is the desktop jvm frontend.

akurasov commented 2 years ago

Data Model could be put to the common module and you can have two separate jvm modules, both referencing it. Will it work for you?

okushnikov commented 2 weeks ago

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