如何使用Gradle复制任务复制到多个目标? [英] How to copy to multiple destinations with Gradle copy task?

查看:924
本文介绍了如何使用Gradle复制任务复制到多个目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Gradle任务将一个文件复制到多个目的地。我在其他网站中发现了以下内容,但运行此任务时出现错误。

  def filesToCopy = copySpec {
from'somefile.jar'
rename {String fileName - > 'anotherfile.jar'}
}

任务copyFile(类型:复制){
with filesToCopy {
到'dest1 /'
}
with filesToCopy {
到'dest2 /'
}
}




错误



方法没有签名:org.gradle.api.internal.file.copy.CopySpecImpl.call()适用对于参数类型

有没有办法在一个Gradle任务中复制到多个目的地?



 <$> 

c $ c> def filesToCopy = copySpec {
from'someFile.jar'
rename {'anotherfile.jar'}
}

任务copyFiles<< {
['dest1','dest2']。each {dest - >
copy {
with filesToCopy
into dest
}
}
}


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.

def filesToCopy = copySpec{
    from 'somefile.jar'
    rename {String fileName -> 'anotherfile.jar'}
}

task copyFile(type:Copy) {
    with filesToCopy  {
      into 'dest1/'
    }
    with filesToCopy  {
      into 'dest2/'
    }
}

ERROR

No signature of method: org.gradle.api.internal.file.copy.CopySpecImpl.call() is applicable for argument types

Is there a way to copy to multiple destinations in one Gradle task?

解决方案

If you really want them in one task, you do something like this:

def filesToCopy = copySpec {
  from 'someFile.jar'
  rename { 'anotherfile.jar' }
}

task copyFiles << {
  ['dest1', 'dest2'].each { dest ->
    copy {
      with filesToCopy
      into dest
    }
  }
}

这篇关于如何使用Gradle复制任务复制到多个目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆