Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conventional way of copying files in Gradle - use Copy task or copy method?

Tags:

gradle

I'm adding a task to deploy war files to Tomcat .. the only thing that the task needs to do is copy the war file to the TOMCAT location.

There 2 ways that I can think of implementing this .. but being new to gradle, I'm not quite sure what's more conventional/right (or if it even matters).

task myCopy(type: Copy)      myCopy.configure {        from('source')        into('target')        include('*.war')     } 

or

task myCopy{   doLast{      copy {        from 'source'        into 'target'        include '*.war'      }      }  } 
like image 709
vicsz Avatar asked Apr 03 '12 21:04

vicsz


People also ask

What is type in Gradle task?

Gradle supports two types of task. One such type is the simple task, where you define the task with an action closure. We have seen these in Build Script Basics. For this type of task, the action closure determines the behaviour of the task. This type of task is good for implementing one-off tasks in your build script.

What is Ziptree 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.

Which of the following files is a Gradle file?

gradle file is located in each module of the android project. This file includes your package name as applicationID , version name(apk version), version code, minimum and target sdk for a specific application module.


1 Answers

In most cases (including this one), the Copy task is the better choice. Among other things, it will give you automatic up-to-date checking. The copy method is meant for situations where (for some reason) you have to bolt on to an existing task and cannot use a separate task for copying.

The code for your Copy task can be simplified to:

task myCopy(type: Copy) {     from('source')     into('target')     include('*.war') } 
like image 83
Peter Niederwieser Avatar answered Sep 21 '22 05:09

Peter Niederwieser