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?
from
and into
accept closures to defer evaluation of arguments, so this should help:
from { fileTree(...).files }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With