0

I'm trying to compile simple Kotlin Gradle script. I've created a project in Idea with build.gradle.kts with following contents:

group = "org.example"
version = "1.0-SNAPSHOT"

tasks {
    register("runScript", Copy::class) {
        from("data")
        into("out")
    }
}

It was inspired by copy sample inside gradle/kotlin-dsl repository and it's not compiling either from IDE or gradlew in terminal. It gives me these errors:

e: /Users/dalexiv/Workspace/script-zipper/build.gradle.kts:5:5: Unresolved reference: register
e: /Users/dalexiv/Workspace/script-zipper/build.gradle.kts:5:27: Unresolved reference: Copy
e: /Users/dalexiv/Workspace/script-zipper/build.gradle.kts:6:9: Unresolved reference: from
e: /Users/dalexiv/Workspace/script-zipper/build.gradle.kts:7:9: Unresolved reference: into

Maybe I missing some kind of plugin to include? How do I do that?

vrfloppa
  • 374
  • 4
  • 14

2 Answers2

0
tasks.register("runScript", Copy::class.java) {
    from("data")
    into("out")
}
milbr
  • 1,015
  • 1
  • 10
  • 16
0

The problem is that you are using Gradle with version lower than 4.10.

In case of gradlew, you can check the file <project>/gradle/wrapper/gradle-wrapper.properties for the value of distributionUrl and change it to version 4.10+, e.g.:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Speaking the IDE, I guess that you are using IntelliJ IDEA (or some sibling). The problem is that the current version of IDEA (2018.2.3) generates - for Gradle Kotlin DSL project - Gradle wrapper with version 4.8, which causes your problem. If your IntelliJ project uses Gradle wrapper, then the solution is the same as the one above.

Another solution could be that you set local gradle distribution with version 4.10+.

enter image description here

Vít Kotačka
  • 1,472
  • 1
  • 15
  • 40