Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy to multiple destinations with Gradle copy task?

Tags:

gradle

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?

like image 415
Venkatesh Nannan Avatar asked Nov 20 '12 06:11

Venkatesh Nannan


People also ask

What is FileTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.

How do I create a zip file in Gradle?

In Gradle, zip files can be created by using 'type: zip' in the task. In the below example, from is the path of source folder which we want to zip. destinationDir is the path of the destination where the zip file is to be created. archiveName is the name of the zip file.

What is Gradle build directory?

The build directory of this project into which Gradle generates all build artifacts. 4. Contains the JAR file and configuration of the Gradle Wrapper.

How do I run a test class in Gradle?

You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.


1 Answers

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     }   } } 
like image 169
ajoberstar Avatar answered Sep 24 '22 23:09

ajoberstar