如何使用gradle中的“复制”任务复制目录

时间:2015-12-14 16:44:25

标签: gradle directory copy

我想将一系列文件和整个目录复制到单个Copy任务中的另一个目录中。我可以复制单个文件和目录的内容,但是如何复制目录呢?

这是我的任务:

task myTask(type: Copy) {
    from 'path/to/file'
    from 'path/to/dir'
    into 'path/to/target'
}

复制文件OK,但只复制dir中的文件。我想在path/to/target/dir(不在path/to/target)中得到目录的内容。

我找到了一个使用的方法:

task myTask(type: Copy) {
    from 'path/to/file'
    from 'path/to'
    into 'path/to/target'
    include 'dir'
}

但这很容易发生名称冲突。我实际上有很多文件和dirs要复制,我想把它作为一项任务。

1 个答案:

答案 0 :(得分:8)

The only solution I know for your problem:

task myTask(type: Copy) {
    into 'path/to/target'
    from 'path/to/file'

    into ('dir') {
       from 'path/to/dir'        
    }
}

Keep in mind that into: ('dir') construction works relatively to path/to/target/ location

相关问题