Working with files
It is very common in a build script that we have to work with files and directories. For example, when we need to copy a file from one directory to another or create a directory to store the output of a task or program.
Locating files
To locate a file or directory relative to the current project, we can use the file()
method. This method is actually a method of the Project
object that is connected to our build script. In the previous chapter, we discussed how to use an explicit reference to the project
variable or simply invoke methods and properties of the Project
object implicitly.
The file()
method will resolve the location of a file or directory relative to the current project and not the current working directory. This is very useful as we can run a build script from a different directory than the location of the actual build script. File or directory references that are returned by the file()
method are then resolved, relative to the project directory.
We can pass any...