How to copy to multiple destinations with Gradle copy task?

前端 未结 5 1177
陌清茗
陌清茗 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:25

    Here is a general snippet without copySpec for Gradle 4.1. As pointed out the trick is to use a base into and use relative into inside the closures (e.g. from closure).

    task multiIntoCopy(type: Copy){
        into(projectDir) // copy into relative to this
    
        from("foo"){
            into("copied/foo") // will be projectDir/copied/foo
            // just standard copy stuff
            rename("a.txt", "x.txt")
        }
    
        from("bar"){
            into("copied/aswell/bar") //  projectDir/copied/copied/aswell/bar
        }
    
        from("baz") // baz folder content will get copied into projectDir
    
        //from("/bar"){ // this will mess things up, be very careful with the paths
        //    into("copied/aswell/bar")
        //}
    }
    

提交回复
热议问题