Using a template in a gradle copy task

I would like to copy the directory using a wildcard, however the from method of the Gradle copy task does not accept the wildcard.

 // this doesn't work task copyDirectory(type: Copy) { from "/path/to/folder-*/" into "/target" } // this does task copyDirectory(type: Copy) { from "/path/to/folder-1.0/" into "/target" } 
+7
gradle
source share
1 answer

Just use the "include" task property to specify the exact files from the directories you need to copy, something like this:

 task copyDirectory(type: Copy) { from "/path/to/" include 'test-*/' into "/target" } 

Update: if you want to copy the contents of directories only, you will have to deal with each file separately, something like this:

 task copyDirectory(type: Copy) { from "/path/to/" include 'test-*/' into "/target" eachFile { def segments = it.getRelativePath().getSegments() as List it.setPath(segments.tail().join("/")) return it } includeEmptyDirs = false } 
+5
source share

All Articles