I have a directory structure like this:
file1.txt file2.txt dir1/ file3.txt file4.txt
I want to use Gradle to copy that entire structure into another directory. I tried this:
task mytest << { copy { from "file1.txt" from "file2.txt" from "dir1" into "mytest" } }
But this results in the following:
mytest/ file1.txt file2.txt file3.txt file4.txt
See, the copy from dir1
copied the files in dir1
, whereas I want to copy dir1
itself.
Is it possible to do this directly with Gradle copy?
So far, I have only been able to come up with this solution:
task mytest << { copy { from "file1.txt" from "file2.txt" into "mytest" } copy { from "dir1" into "mytest/dir1" } }
For my simple example there's not much to it, but in my actual case there are many directories I want to copy, and I'd like to not have to repeat so much.
A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
The difference lies in the fact that ./gradlew indicates you are using a gradle wrapper. The wrapper is generally part of a project and it facilitates installation of gradle.
On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.
You can use .
as the directory path and include
to specify, which files and directories you want to copy:
copy { from '.' into 'mytest' include 'file*.txt' include 'dir1/**' }
If both from
and into
are directories, you'll end up with the full copy of the source directory in the destination directory.
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