How to copy to multiple destinations with Gradle copy task?

前端 未结 5 1156
陌清茗
陌清茗 2020-12-05 04:02

I am trying to copy one file to multiple destinations through a Gradle task. I found the following in other websites but I get an ERROR while running this task.



        
5条回答
  •  春和景丽
    2020-12-05 04:26

    With a Common Destination Base Path

    If your destination paths share a common path prefix (dest_base), then you can use something like this:

    def filesToCopy = copySpec {
        from 'somefile.jar'
        rename { String fileName -> 'anotherfile.jar' }
    }
    
    task copyFile(type: Copy) {
        into 'dest_base'
        into('dest1') {
          with filesToCopy
        }
        into('dest2') {
          with filesToCopy
        }
    }
    

    Compared to other answers which use the copy method, this approach also retains Gradle’s UP-TO-DATE checks.

    The above snippet would result in output like this:

    dest_base/
    ├── dest1
    │   └── anotherfile.jar
    └── dest2
        └── anotherfile.jar
    

提交回复
热议问题