Having some issues with my multiplatform project, ...
# multiplatform
m
Having some issues with my multiplatform project, trying to run the JVM main function in IntelliJ runs compileJava, but that seems to error, listing only the Android compileJava tasks:
Copy code
Cannot locate tasks that match ':ac-frontend:compileJava' as task 'compileJava' is ambiguous in project ':ac-frontend'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac', 'compileDebugUnitTestJavaWithJavac', 'compileReleaseJavaWithJavac', 'compileReleaseUnitTestJavaWithJavac'.
If I add
withJava
to my
kotlin { jvm { ... }}
configuration, it complains it conflicts with the Android plugin. What do I do in this situation?
v
can you post whole build.gradle(.kts)?
You can take a look here https://github.com/wojta/hello-kotlin-multiplatform where I have each application platform as a separate module (using statndard Android and java application Gradle plugins) and a multiplatform shared module.
m
Copy code
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    id("org.jetbrains.compose") version "1.2.1"
    id("com.android.application")
}

val development by transformedProperty { it != "false" }

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

kotlin {
    js("web", IR) {
        browser {
            commonWebpackConfig {
                outputFileName = "app.js"
            }
        }
        binaries.executable()
    }

    jvm("desktop") {

    }

    android("app") {

    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":ac-common"))

                implementation(compose.ui)
                implementation(compose.foundation)
                implementation(compose.material)
                implementation(compose.runtime)

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

                implementation("io.ktor:ktor-client-core:2.2.1")
                implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.1")
                implementation("io.ktor:ktor-client-content-negotiation:2.2.1")
            }
        }

        val webMain by getting {
            dependsOn(commonMain)
            dependencies {
                implementation(compose.web.core)
                implementation(compose.web.svg)

                implementation("io.ktor:ktor-client-js:2.2.1")
            }
        }

        val jvmMain by creating {
            dependsOn(commonMain)
            dependencies {
                implementation("io.ktor:ktor-client-cio:2.2.1")
            }
        }

        val desktopMain by getting {
            dependsOn(jvmMain)

            dependencies {
                implementation(compose.desktop.currentOs)
                implementation("ch.qos.logback:logback-classic:1.4.5")
            }
        }

        val appMain by getting {
            dependsOn(jvmMain)

            dependencies {
                // Avoid changing these as they change the minSdkVersion and become incompatible
                implementation("androidx.appcompat:appcompat:1.5.1")
                implementation("androidx.activity:activity-compose:1.5.0")
            }
        }
    }
}

compose.desktop {
    application {
        mainClass = "dev.anarchy.app.MainKt"

        nativeDistributions {
            packageName = "AnarchyChess"
            description = "Chess but 2"
            copyright = "© 2022 Anarchy Chess Developers. All rights reserved."
            licenseFile.set(rootDir.resolve("LICENSE"))

            outputBaseDir.set(rootProject.buildDir.resolve("dist"))
            modules("java.instrument", "jdk.unsupported")

            targetFormats(
                // MacOS
                TargetFormat.Dmg,
                // Windows
                TargetFormat.Msi,
                // Linux
                TargetFormat.Deb,
            )

            windows {
                perUserInstall = true
                dirChooser = true
            }
            linux {

            }
            macOS {
                bundleID = group as String
            }
        }

        buildTypes.release.proguard {
            configurationFiles.from(projectDir.resolve("<http://proguard-desktop-rules.pro|proguard-desktop-rules.pro>"))
        }
    }
}

compose.experimental {
    web.application { }
}

android {
    compileSdk = 32

    defaultConfig {
        minSdk = 26
        targetSdk = 32
        versionName = project.version as String
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    buildTypes {
        debug {
            versionNameSuffix = "-debug"
            proguardFiles(getDefaultProguardFile("proguard-defaults.txt"), projectDir.resolve("<http://proguard-android-rules.pro|proguard-android-rules.pro>"))
        }
        release {
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), projectDir.resolve("<http://proguard-android-rules.pro|proguard-android-rules.pro>"))
        }
    }

    sourceSets {
        named("main") {
            manifest.srcFile("src/appMain/AndroidManifest.xml")
            res.srcDirs("src/appMain/res")
        }
    }
}

tasks {
    named("preBuild") {
        dependsOn("clean")
    }

    named("build") {
        if (development) {
            dependsOn(
                // Android
                "assembleDebug",
                // Desktop
                "packageDistributionForCurrentOS",
                // Web is handled by ac-backend
            )
        } else {
            dependsOn(
                // Android
                "assembleRelease",
                // Desktop
                "packageReleaseDistributionForCurrentOS",
                // Web is handled by ac-backend
            )
        }
    }
}
Ideally these all stay within the same subproject rather than separating them all out
e
Try
compileJvmJava
. I don't know the exact one but you can run
gradlew tasks
to see all tasks
m
Unfortunately I don't control which task IntelliJ uses when I hit the build button
e
You can use a run configuration to control what happens when you build
m
Where would I configure which task Ctrl+9 runs?
e
I don't know what that maps to in your IDE (everyone can configure theirs differently) but you're looking for the "Run" command (you can see what maps to the in the Keymap section of settings). Then there's a drop-down somewhere in the IDE menus (mine is on the top, but it is customizable so no guarantee that it's in the same place for you) that shows what will get run. You can change the type of configuration and what the settings are for each one.
m
You're referring to the run configurations, which I'm aware can be customized. I'm asking about the Build Project button just to the left of that dropdown, because from what I can tell it simply always runs compileJava.
e
There won't be a
compileJava
task with KMP so unless there's some way to configure that it won't be of much use