Is it possible to limit the contents of the "snapshot" made of the target directory for UP-TO-DATE checks on a Copy task?

I have a simple copy task:

task copyWebToBin(type: Copy, dependsOn: jar) {
    into myBinDir
    from sourceSets.main.resources
    include 'web/**'

The problem is that the target ‘myBinDir’ is a VERY large directory structure (with thousands of files in sub-directories), and the UP-TO-DATE check takes some time to produce the snapshot.

Is there any way to limit the content of that snapshot operation?

I tried the following approach:

task copyWebToBin(type: Copy, dependsOn: jar) {
    includeEmptyDirs = false
    into "$myBinDir/web"
    from sourceSets.main.resources.getSourceDirectories().asFileTree.matching {
        include 'web/**'
    eachFile { FileCopyDetails fcp ->
        fcp.relativePath = new RelativePath(!fcp.isDirectory(), (String[]) fcp.relativePath.segments[1..-1].toArray())

And, the UP-TO-DATE check now runs in .001 seconds, but all of that was pretty cumbersome (and I do copy operations like this in a lot of places in the build). So, I was wondering if there’s an easier or less verbose way to accomplish the same thing.

Hi Larry,

if you don’t care about the up-to-date check at all, you can use the Project.copy method to copy the files around. As a consequence, the task would execute every time even if there are no changes to the resources.

I guess something like the contributor wants to add here would help you?


Yeah, that looks like it might be a potential solution. For now, I’m just using the more verbose idiom I posted since there are other parts of the build that do need to check for changes in the entire directory, and the “always copy” you suggest would cause them to trigger.

Thanks, Larry.