简体   繁体   English

Gradle Kotlin:如何将 build.gradle 脚本的一部分从 groovy 转换为 build.gradle.kts 语法?

[英]Gradle Kotlin : How to convert part of build.gradle script from groovy to build.gradle.kts syntaxe?

Below a piece of groovy code :下面是一段常规代码:

compileKotlin2Js.kotlinOptions {
    moduleKind = "commonjs"
    outputFile = "node/crypto.js"
}

it gives the following error :它给出了以下错误:

Script compilation errors:

  Line 44: compileKotlin2Js.kotlinOptions {
           ^ Unresolved reference: compileKotlin2Js

  Line 45:     moduleKind = "commonjs"
               ^ Unresolved reference: moduleKind

  Line 46:     outputFile = "node/crypto.js"
               ^ Unresolved reference: outputFile

How to translate it to kotlin syntaxe ?如何将其转换为 kotlin 语法?

Does this work for you?这对你有用吗?

tasks {
    "compileKotlin2Js"(Kotlin2JsCompile::class)  {
        kotlinOptions.metaInfo = true
    }
}

Not sure how you're set up, but you should be able to add this to the top of your build script:不确定你是如何设置的,但你应该能够将它添加到构建脚本的顶部:

import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

Then do:然后做:

tasks.withType<Kotlin2JsCompile>() {
    kotlinOptions {
        moduleKind = "commonjs"
        outputFile = "node/crypto.js"
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解析和修改 build.gradle.kts Kotlin Gradle 构建脚本? - How to parse and modify build.gradle.kts Kotlin Gradle build script? 如何定义 settings.gradle.kts 和 build.gradle.kts 中可用的 kotlin dsl gradle 属性? - How to define kotlin dsl gradle properties available in settings.gradle.kts and build.gradle.kts? 将 Groovy 任务 build.gradle 转换为 kotlin kts 文件 - Converting Groovy tasks build.gradle to kotlin kts file 如何在 build.gradle.kts 和 kotlin 中使用 JUnit 5? - How to use JUnit 5 with build.gradle.kts and kotlin? Jaxb 用于 build.gradle.kts。 如何将它从 groovy 翻译成 kotlin? - Jaxb for build.gradle.kts. How to translate it from groovy to kotlin? 将 kotlin dsl gradle 转换为 groovy build.gradle - convert kotlin dsl gradle to groovy build.gradle 如何在 buildSrc/build.gradle.kts、settings.gradle.kts 和 build.gradle.kts 中导入辅助类? - How to import a helper class in buildSrc/build.gradle.kts, settings.gradle.kts, and build.gradle.kts? 如何在 build.gradle.kts 中设置 gradle 任务以在 Kotlin(1.4) 多平台项目中创建 fatJar - how to set up a gradle task to create fatJar in Kotlin(1.4) Multiplatform project in build.gradle.kts 将 build.gradle 迁移到 build.gradle.Kts:无法解析 Properties 类 - Migrating the build.gradle to build.gradle.Kts : Not able to resolve Properties class 如何将保护级别 build.gradle 的文件从 Gradle Groovy 迁移到 Gradle Kotlin DSL - How to migrate protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM