Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle filetree lazy flat copy

I have a task that needs to copy files that are created during the execution phase (they're products of a gcov unit-testing phase) into another directory. At the moment, my code will only execute properly the second time it is executed (i.e. when files in the directory structure have been created). The first time round, however, I get a "skipping task, no source files" debug message.

task copyGcovObj(type: Copy, dependsOn: 'test') {
    description "Copies gcov files into build/testOutput directory."
    from fileTree(dir: "$buildDir/objectFiles", includes: ["**/*.gcno", "**/*.gcda"]).files
    into ("$buildDir/testOutput")
}

The code is taken from here: Flat copy. The task 'test' referred to is a task that executes the unit tests.

I think the problem is that during the configuration phase, there are no files to copy, so Gradle skips the task. If it is executed a second time, Gradle sees there are files, so executes the copy. How can I make it so that Gradle executes the copy, but the files to be copied are determined at the execution phase?

like image 745
John Avatar asked Dec 19 '22 14:12

John


1 Answers

from and into accept closures to defer evaluation of arguments, so this should help:

from { fileTree(...).files }
like image 110
Peter Niederwieser Avatar answered Dec 26 '22 10:12

Peter Niederwieser