gradlekotlinshadowjar

Not work "include" in Kotlin script: ^ Unexpected tokens (use ';' to separate expressions on the same line)


In my build.gradle.kts:

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

But I get error:

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

Solution

  • Need to use double quotes for strings and (...) around function arguments. It is the first 2 things mentioned in the docs for converting Groovy build scripts to Kotlin. https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/#prepare_your_groovy_scripts

    Prepare your Groovy scripts

    Some simple Kotlin and Groovy language differences can make converting scripts tedious:

    • Groovy strings can be quoted with single quotes 'string' or double quotes "string" whereas Kotlin requires double quotes "string".

    • Groovy allows to omit parentheses when invoking functions whereas Kotlin always requires the parentheses.