Copy entire directory in Gradle

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.


I know this is a bit late, but I tried @Andrew solution above and it copied everything inside the directory. "." is not required nowadays to represent a direct in gradle. So I did some research and found this

and created the following code (with Up-to-date check) based on it:

task resourcesCopy() {
    doLast {
        copy {
            from "src/main/resources"
            into "./target/dist/WEB-INF/classes"
        }
        copy {
            from "GeoIP2.conf"
            into "./target/dist/WEB-INF"
        }
    }
}

Tags:

Gradle