Gradle Kotlin多平台构建脚本问题
我正在尝试将groovy构建脚本迁移到kotlin以用于我的jvm/js-multiplatform项目,但我有以下例外 org.gradle.api.UnknownTaskException:在根项目“TradeProject”中找不到名为“jsBrowserProductionWebpack”的任务。 build.gradle.ktsGradle Kotlin多平台构建脚本问题,gradle,kotlin-multiplatform,Gradle,Kotlin Multiplatform,我正在尝试将groovy构建脚本迁移到kotlin以用于我的jvm/js-multiplatform项目,但我有以下例外 org.gradle.api.UnknownTaskException:在根项目“TradeProject”中找不到名为“jsBrowserProductionWebpack”的任务。 build.gradle.kts buildscript { repositories { jcenter() } } plugins { id(&q
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())
}
settings.gradle.kts
rootProject.name = "TradeProject"
项目结构
试试这个
//在我们生成的任何JAR中包含JS工件
tasks.getByName<Jar>("jvmJar") {
val taskName = if (project.hasProperty("isProduction")) {
"jsBrowserProductionWebpack"
} else {
"jsBrowserDevelopmentWebpack"
}
val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
dependsOn(webpackTask) // make sure JS gets compiled first
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
}
tasks.getByName(“jvmJar”){
val taskName=if(project.hasProperty(“isProduction”)){
“jsBrowserProductionWebpack”
}否则{
“jsBrowserDevelopmentWebpack”
}
val webpackTask=tasks.getByName(taskName)
dependsOn(webpackTask)//确保先编译JS
from(文件(webpackTask.destinationDirectory,webpackTask.outputFileName))//将输出文件带到JAR中
}
您使用的IDE和版本是什么?@NestorLedon Intellij IDEA 2020.1
tasks.getByName<Jar>("jvmJar") {
val taskName = if (project.hasProperty("isProduction")) {
"jsBrowserProductionWebpack"
} else {
"jsBrowserDevelopmentWebpack"
}
val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
dependsOn(webpackTask) // make sure JS gets compiled first
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
}