Hi. when trying to show preview in Fleet it shows ...
# fleet
g
Hi. when trying to show preview in Fleet it shows
e: Kotlin Target 'jvm()' is already declared.
error. Any ideas how to fix?
Copy code
e: Kotlin Target 'jvm()' is already declared.
<====---------> 33% CONFIGURING [4
Declaring multiple Kotlin Targets of the same type is not supported.

Read <https://kotl.in/declaring-multiple-targets> for details.

e: Kotlin Target 'jvm()' is already declared.
> :multiplatform-ui:generateA
Declaring multiple Kotlin Targets of the same type is not supported.

Read <https://kotl.in/declaring-multiple-targets> for details.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':parser:checkKotlinGradlePluginConfigurationErrors'.
> Kotlin Gradle Plugin reported errors. Check the log for details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.

BUILD FAILED in 2s
Closed process
w
Hmm, thanks for reaching out first of all! We try to detect whether your project has a JVM target. When we do not find a JVM target, we will create one just for the preview build. Is it correct that you already have a JVM target? In that case we have not been able to detect it... Also, do you have an Android target? In this case you might be able to try running Android preview.
g
no Android target. this is the build file
Copy code
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.composeCompiler)
}

kotlin {
    jvm("desktop")
    
    @OptIn(ExperimentalWasmDsl::class)
    wasmJs {
        moduleName = "composeApp"
        browser {
            val rootDirPath = project.rootDir.path
            val projectDirPath = project.projectDir.path
            commonWebpackConfig {
                outputFileName = "composeApp.js"
                devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
                    static = (static ?: mutableListOf()).apply {
                        // Serve sources to debug inside browser
                        add(rootDirPath)
                        add(projectDirPath)
                    }
                }
            }
        }
        binaries.executable()
    }
    
    sourceSets {
        val desktopMain by getting
        
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
            implementation(libs.androidx.lifecycle.viewmodel)
            implementation(libs.androidx.lifecycle.runtime.compose)
        }
        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
            implementation(libs.kotlinx.coroutines.swing)
        }
    }
}


compose.desktop {
    application {
        mainClass = "org.example.project.MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "org.example.project"
            packageVersion = "1.0.0"
        }
    }
}
already have
jvm("desktop")
w
Hmm, that looks a lot like a project from kmp.jetbrains.com with Desktop and Web selected. Am I correct that you based it on this template? I tried it, and I can run the preview for the
App
function in
commonMain
. Which version of Fleet are you using?
g
it is an old project, about 2 years adn wanted to update it. Decided to download project from that website and copy pasted build files. All works, project runs including tests
not sure what I could miss
yep, I did miss something. Preview works with the project I copied build files from
w
Thanks for sharing the project, that was extremely useful, I was able to reproduce the error! :) I filed a bug for this: https://youtrack.jetbrains.com/issue/FL-31343/Kotlin-target-jvm-is-already-declared-build-error-for-Compose-Dekstop-preview
g
so what now? any workaround? only idea I have now is to add android target and use AS for previews
w
Yeah I have been digging around and I don't see a direct workaround right now. You could indeed add an Android target and use the Android preview in either AS or Fleet. Sorry for the inconvenience :(
g
nah its ok
btw is it because of module names? or because of missing code block that I forgot to copy?
I could rename modules if it is because of naming
w
No, it's a straight up bug. Some Gradle logic that I really thought worked, does not work somehow 😅. I'm sorry Giorgi, I'm on it! But I doubt that these sketchy Gradle changes will qualify for hotfixes, so it'll take a while until the fix will land in your Fleet's release I think.
g
ok. Good luck