YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Interacting With The File System

Get Embed Code
4 Languages

Showing Revision 53 created 05/25/2016 by Udacity Robot.

  1. Coping files in Gradle is simple.

  2. We start by simply declaring a new task,
    and
  3. specifying the type of the task as Copy.
  4. Of course this task won't
    actually do anything,
  5. because we haven't told it what file
    we'd like copied, and to where.
  6. Simplest example is to copy
    the contents of one folder to another.
  7. We use the copy tasks from
    method to add sources, and
  8. the into method to
    specify the destination.
  9. This copy task will copy
    the contents of the images directory
  10. into the build directory.
  11. We can specify files to include or
    exclude, our filters can use wild cards,
  12. allowing us to do things like, include
    all files that match a certain pattern,
  13. or have a particular file extension.
  14. This combination of source,
  15. destination, inclusions and
    exclusions is called a copy spec.
  16. Let's configure our task to
    only include jpeg images,
  17. by calling the include method,
    and passing a file pattern.
  18. We can also configure a single copy
    task to copy from multiple sources.
  19. Copy specs can be hierarchical, which
    is particularly useful when you want to
  20. exclude certain files from
    a particular sub-folder, or
  21. a specific Include them in another.
  22. Let's configure a copy task which
    copies all JPEGs into one folder, and
  23. all GIFs into another.
  24. We define two child copy specs.
  25. One to include only JPEG files, and
    the other to include only GIFs.
  26. We also specify the folder we
    want to copy these files into.
  27. These folders will be created as
    subfolders, under the root copy
  28. destination, the result being that
    JPEGs will be copied to build/jpeg, and
  29. all GIFT files will be
    copied to build/gif.
  30. Gradle provides task types for
    creating archives like ZIP or TAR files.
  31. Archive tasks are nearly identical to
    copy tasks, except instead of specifying
  32. a destination directory,
    we specify an archive name.
  33. Let's zip up all files
    in out images directory.
  34. We use the Zip task base name,
    and destinationDir properties
  35. to tell Gradle what to name the archive,
    and where to create it.
  36. Note the the destinationDir
    property takes a Java file object.
  37. Luckily, the Gradle project interface
    provides a convenience method for
  38. creating files.
  39. We can do similar things with
    archive tasks and trial copy specs.
  40. We can create an archive
    which puts JPEGs and
  41. GIFs into their own
    directories inside the archive.
  42. The only difference from
    our copy task example,
  43. is that we specify the archive name and
    the destination.
  44. Sometimes we want to delete
    files during our builds,
  45. usually to clean up
    previous build outputs.
  46. We can use the delete task to delete
    files or folders in our project.
  47. Here we have a task that
    deletes the build folder.