Why I cannot set Copy.destinationDir property?


(aleksg) #1

I cannot understand something in configuring tasks.
For example I create task
task myCopy(type: Copy) {
from(“myDir”) {
rename("$jarName", “$jarFinalName”)
}
destinationDir("$rootDir/publish/")
}

because I see property destinationDir on this page
https://docs.gradle.org/3.3/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:destinationDir

But I get an error saying

Could not find method destinationDir() for arguments [publish] on task ‘:prepareJar’ of type org.gradle.api.tasks.Copy.

If I change it to ‘into’ then all is well.
Why I have to use ‘into’ instead of property ‘destinationDir’ described in docs?


(Schalk Cronjé) #2

setDestinationDir requires a File object and you are passing a GString. It is better to use into as it takes an Object and allows for lazy-evaluation.


(aleksg) #3

thanks for helping me