Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy entire directory in Gradle

Tags:

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.

like image 254
Kip Avatar asked Aug 23 '16 20:08

Kip


People also ask

What is FileTree in gradle?

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.

What is ProcessResources in gradle?

Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.

What is difference between gradle and Gradlew?

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.

How do I change directory in gradle?

On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.


1 Answers

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.

like image 137
Andrew Lygin Avatar answered Oct 13 '22 07:10

Andrew Lygin