Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Move a folder from ABC to XYZ

Directory Structure:

Project1/ABC/file1.txt

I want the above ABC folder moved/renamed to XYZ (without leaving ABC there).

How can I do this using Gradle. Seems like in Gradle: For a right hand person, it's itching your right ear using your left hand, taking it across top of your head.

I have used the following example: but it doesn't do anything:

task renABCToXYZ(type: Copy) << {
   copy {
      from "Project1"
      into "Project1"
      include 'ABC'
      rename ('ABC', 'XYZ')
   }
}
like image 869
AKS Avatar asked Dec 31 '13 23:12

AKS


People also ask

How do I move files in Gradle?

Move by either by dragging and dropping while holding the Shift key, or using the File Explorer context menu (normally right-click) and selecting cut, and then paste to the new location.

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.

What is rootDir in Gradle?

rootDir. The root directory of this project. The root directory is the project directory of the root project.

How do I change the home directory in Gradle?

Set the GRADLE_USER_HOME environment variable to new path. On android studio just go to File > Settings > Build Execution, Deployment > Gradle > Service directory path choose directory what you want.


1 Answers

Your task declaration is incorrectly combining the Copy task type and project.copy method, resulting in a task that has nothing to copy and thus never runs. Besides, Copy isn't the right choice for renaming a directory. There is no Gradle API for renaming, but a bit of Groovy code (leveraging Java's File API) will do. Assuming Project1 is the project directory:

task renABCToXYZ {
    doLast {
        file("ABC").renameTo(file("XYZ"))
    }
}

Looking at the bigger picture, it's probably better to add the renaming logic (i.e. the doLast task action) to the task that produces ABC.

like image 179
Peter Niederwieser Avatar answered Oct 27 '22 14:10

Peter Niederwieser