Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a wildcard in gradle copy task

Tags:

gradle

I'd like to copy a directory using a wildcard, however the from method of the Gradle copy task doesn't accept a 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"
}
like image 997
pnewhook Avatar asked Dec 05 '16 22:12

pnewhook


People also ask

How do I create a zip file in Gradle?

In Gradle, zip files can be created by using 'type: zip' in the task. In the below example, from is the path of source folder which we want to zip. destinationDir is the path of the destination where the zip file is to be created. archiveName is the name of the zip file.

What is .Gradle directory?

The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.

What is task in Gradle?

The work that Gradle can do on a project is defined by one or more tasks. A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.


1 Answers

Just use 'include' task property to specify exact files ot 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 only directories content, then you have to deal with every 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
}
like image 129
Stanislav Avatar answered Sep 17 '22 13:09

Stanislav