Kotlin проблема сценария мультиплатформенной сборки - PullRequest
1 голос
/ 02 августа 2020

Я пытаюсь перенести сценарий сборки groovy на kotlin для моего jvm / js - многоплатформенного проекта, но у меня есть следующее исключение

org.gradle.api. UnknownTaskException: задача с именем jsBrowserProductionWebpack не найдена в root проекте TradeProject

build.gradle.kts

buildscript {
    repositories {
        jcenter()
    }
}

plugins {
    id("org.jetbrains.kotlin.multiplatform") version "1.3.72"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.3.72"
    id("distribution")
    id("war")
}

repositories {
    jcenter()
    maven("https://dl.bintray.com/kotlin/ktor")
    mavenCentral()
}

val ktorVersion = "1.3.2"
val logBackVersion = "1.2.3"

kotlin {
    jvm {
        compilations.named("main") {
            tasks.getByName<Copy>(processResourcesTaskName) {
                dependsOn("jsBrowserProductionWebpack")
                tasks.named<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("jsBrowserProductionWebpack") {
                    from(entry?.name, destinationDirectory)
                }
            }
        }
    }
    js {
        browser {
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation(kotlin("stdlib-common"))
            }
        }

        commonTest {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }

        jvm().compilations["main"].defaultSourceSet {
            dependencies {
                implementation(kotlin("stdlib-jdk8"))
                implementation("io.ktor:ktor-server-netty:$ktorVersion")
                implementation("io.ktor:ktor-server-servlet:$ktorVersion")
                implementation("io.ktor:ktor-html-builder:$ktorVersion")
                implementation("ch.qos.logback:logback-classic:$logBackVersion")
                implementation("io.ktor:ktor-client-core:$ktorVersion")
            }
        }

        jvm().compilations["test"].defaultSourceSet {
            dependencies {
                implementation(kotlin("test"))
                implementation(kotlin("test-junit"))
            }
        }

        js().compilations["main"].defaultSourceSet {
            dependencies {
                implementation(kotlin("stdlib-js"))
                implementation(kotlin("io.ktor:ktor-client-js:$ktorVersion"))
            }
        }

        js().compilations["test"].defaultSourceSet {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
    }

}

tasks.register<JavaExec>("run") {
    dependsOn("jvmJar")
    group = "application"
    main = "sample.SampleJvmKt"
    val t = tasks.named<Jar>("jvmJar")

    classpath(configurations.named("jvmRuntimeClasspath"), t.get())
}

build.gradle (отлично работает)

buildscript {
    repositories {
        jcenter()
    } }

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.72'
    id 'distribution'
    id 'war' } repositories {
    jcenter()
    maven { url "https://dl.bintray.com/kotlin/ktor" }
    mavenCentral() }



//webAppDirName = 'webapp'

def ktor_version = '1.3.2' def logback_version = '1.2.3'

kotlin {
    jvm()
    js {
        browser {
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')

            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        jvmMain {
            dependencies {
                implementation kotlin('stdlib-jdk8')
                implementation "io.ktor:ktor-server-netty:$ktor_version"
                implementation "io.ktor:ktor-server-servlet:$ktor_version"
                implementation "io.ktor:ktor-html-builder:$ktor_version"
                implementation "ch.qos.logback:logback-classic:$logback_version"
                implementation "io.ktor:ktor-client-core:$ktor_version"

            }
        }
        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        jsMain {
            dependencies {
                implementation kotlin('stdlib-js')
                implementation "io.ktor:ktor-client-js:$ktor_version"
            }
        }
        jsTest {
            dependencies {
                implementation kotlin('test-js')
            }
        }
    } }

jvmJar {
    dependsOn(jsBrowserProductionWebpack)
    from(new File(jsBrowserProductionWebpack.entry.name, jsBrowserProductionWebpack.outputPath)) }

task run(type: JavaExec, dependsOn: [jvmJar]) {
    group = "application"
    main = "sample.SampleJvmKt"
    classpath(configurations.jvmRuntimeClasspath, jvmJar)
    args = [] }

settings.gradle.kts

rootProject.name = "TradeProject"

Структура проекта

введите описание изображения здесь

...