Copy task doesn't update multiple destinations properly


(Jeff Sussna) #1

Given a copy task that writes to two destinations, if the second destination is considered up-to-date, the first destination won’t get written. Example:

task copyTwo (type:Copy) {

from ‘src’

into “dst1” // won’t get updated if dst2 is up to date, even if dst1 is not up to date

into “dst2”

include(‘foo.txt’) } Currently running 1.0-milestone-3


(Jeff Sussna) #2

On further investigation, it looks like copy doesn’t actually support multiple destinations. Instead it appears to ignore the first one altogether. If I delete the contents of dst1 and dst2, then run copy, nothing gets written to dst1.


(Peter Niederwieser) #3

If you simply configure “into” twice, the latter value will override the former. But there are ways to achieve what you want. One solution is to have two tasks, and share common configuration with a copy spec:

def spec = copySpec {
  from "src"
  include "foo.txt"
}
  task copy1(type: Copy) {
  into "dst1"
  with spec
}
  task copy2(type: Copy) {
  into "dst2"
  with spec
}

Another solution is to use so-called child specs:

task copy3(type: Copy) {
    into "."
    include "foo.txt"
      from("src") {
        into "dst1"
    }
    from("src") {
        into "dst2"
    }
}

The “into ‘.’” is currently necessary to prevent Gradle from complaining about an unspecified destination dir.