A Copy task that is non-recursive?


(tinkerer.tech) #1

By default, the Copy task copies everything recursively from the directory specified in its from() method -

task copyTask(type: Copy) {
    from 'src/main/webapp'
    into 'build/explodedWar'
}

The from() method accepts any of the arguments that the files() method does. When an argument resolves to a directory, everything under that directory (but not the directory itself) is recursively copied into the destination directory. When an argument resolves to a file, that file is copied into the destination directory. When an argument resolves to a non-existing file, that argument is ignored.

I am wondering if there’s a way to over-ride this default behaviour, perhaps with an exclude pattern, etc. to copy just the files from the top-level directory? I looked at the user-guide but nothing jumped up in the first few minutes of me looking at it.


(René Groeschke) #2

Hello, you can add a filter to achieve your goals:

task copyTask(type: Copy) {
    from 'src/main/webapp'
    into 'build/explodedWar'
    include "*.*"
}

regards, René


(tinkerer.tech) #3

Yeah that worked!