I currently have a set of copy tasks that take the following form:
task copyFiles {
doLast {
['debug', 'release'].each { config ->
copy {
def filePath = "${distributionArea}/${config}"
from "build/dependencies/foo.lib"
into "${filePath}"
}
copy {
def filePath = "${distributionArea}/${config}"
from "build/dependencies/foo.dll"
into "${filePath}"
}
}
}
}
When I run the build for a first time and this task gets run, I’m finding that the foo.lib file is copied ok, but the foo.dll file isn’t. If I run for a second time, without cleaning, foo.dll is the copied. There are no errors in the logs. One thing to point out, foo.lib is fairly small ~2MB, foo.dll is closer to 55MB.
Are copies blocking? Can anyone think what might be causing the issue?
I’m running 6.6.1.
Thanks in advance and let me know if I can provide any further details.
What I think may be happening is that the lib and dll are produced by different tasks and that you got lucky that the task producing the lib was executed before your copyFiles task, but the dll producing task ran after. The second time you run your task the dll from the previous run is copied. Can you confirm whether that’s happening or not?
You task should have dependencies on the task(s) that produce the lib/dll.
Hi Chris, thanks for responding, I think I solved this today. I actually made a slight mistake in the example code above, it should have read:
task copyFiles {
doLast {
['debug', 'release'].each { config ->
copy {
def filePath = "${distributionArea}/${config}/lib"
from "build/dependencies/foo.lib"
into "${filePath}"
}
copy {
def filePath = "${distributionArea}/${config}/bin"
from "build/dependencies/foo.dll"
into "${filePath}"
}
}
}
}
I’d left off the bin (for dll) and lib (for lib) sub directories in the original post. I then had a subsequent copy task, let’s called it copyTheRest that ran after copyFiles. Because copyTheRest was also copying things into ${distributionArea}/${config}/bin this led to a stale file check and the directory was deleted before copyTheRest ran. This meant that foo.dll that was copied over first, was then wiped out. It worked the second time because copyTheRest was up to date, didn’t run, and therefore didn’t delete the directory foo.dll was written to.
I’ve “fixed” this by ensuring copyFiles now runs after copyTheRest but I think the right way of doing it is to define the outputs of the copyFiles task.