Папки и файлы

Плагины

plugins {
    kotlin("multiplatform") version "1.8.0"
    id("io.kotest.multiplatform") version "5.5.4"
    kotlin("plugin.serialization") version "1.8.0"
    application
}

Сборка серверной части

kotlin {
    jvm {
        withJava()
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }

Сборка клиентской части

    js(IR) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport {
                    enabled.set(true)
                }
            }
        }
    }

Библиотеки для общего кода

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("org.jetbrains.kotlinx:
        kotlinx-serialization-json:$serializationVersion")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }

Библиотеки для серверной части

        val jvmMain by getting {
            dependencies {
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-server-html-builder-jvm:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:$kotlinHtmlVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
            }
        }

Библиотеки для тестирования сервера

        val jvmTest by getting {
            dependencies {
implementation("io.ktor:ktor-server-test-host:$ktorVersion")
implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
            }
        }

Библиотеки для клиентской части

        val jsMain by getting { dependencies {
implementation( project.dependencies.enforcedPlatform(
    "$kotlinWrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"
))
implementation("$kotlinWrappers:kotlin-emotion")
implementation("$kotlinWrappers:kotlin-react")
implementation("$kotlinWrappers:kotlin-react-dom")
implementation("$kotlinWrappers:kotlin-react-router-dom")
implementation("$kotlinWrappers:kotlin-react-redux")
implementation("$kotlinWrappers:kotlin-tanstack-react-query")
implementation("$kotlinWrappers:kotlin-tanstack-react-query-devtools")
implementation(npm("cross-fetch", "3.1.5"))
        }}

Запуск приложения

application {
    mainClass.set("ru.altmanea.webapp.ServerKt")
    applicationDefaultJvmArgs = listOf("-Dio.ktor.development=true")
}

Сборка клиентской части

//tasks.named<Copy>("jvmProcessResources") {
//    val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
//    from(jsBrowserDistribution)
//}

tasks.register<Copy>("buildClient") {
    dependsOn("jsBrowserDevelopmentWebpack")
    from("$buildDir/developmentExecutable/")
    into("$buildDir/processedResources/jvm/main/")
}
tasks.named("run") {
    dependsOn("buildClient")
}