【问题标题】:Not work "include" in Kotlin script: ^ Unexpected tokens (use ';' to separate expressions on the same line)在 Kotlin 脚本中“包含”不起作用:^ 意外标记(使用 ';' 分隔同一行上的表达式)
【发布时间】:2019-08-04 04:06:36
【问题描述】:

在我的 build.gradle.kts 中:

   val shadowJar by tasks.getting(ShadowJar::class) {
    include '*.properties'
}

但我得到错误:

Script compilation errors:

  Line 93:     include '*.properties'
                       ^ Unexpected tokens (use ';' to separate expressions on the same line)

  Line 93:     include '*.properties'
               ^ Function invocation 'include(...)' expected

2 errors
Open File

【问题讨论】:

    标签: gradle kotlin shadowjar


    【解决方案1】:

    需要对字符串使用双引号并在函数参数周围使用 (...)。这是文档中提到的将 Groovy 构建脚本转换为 Kotlin 的前两件事。 https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/#prepare_your_groovy_scripts

    准备你的 Groovy 脚本

    一些简单的 Kotlin 和 Groovy 语言差异可能会使转换脚本变得乏味:

    • Groovy 字符串可以用单引号 'string' 或双引号 "string" 引用,而 Kotlin 需要双引号 "string"。

    • Groovy 允许在调用函数时省略括号,而 Kotlin 总是需要括号。

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 2018-01-15
      • 1970-01-01
      • 2017-10-28
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2017-05-24
      相关资源
      最近更新 更多