Anup Puranik
Anup Puranik

Reputation: 165

Gradle - Accessing files outside the project

This is a very simple question really but I am having to pull my hair over it.

In Gradle, I am having to copy some files in my project to a location outside the project - /var/tmp/a_particular_folder/

The target path will remain the same on both Windows and Linux boxes.

So my task looks like this:

task copyFilesNeededForTests(type: Copy) {
    from 'src/testconfiguration/'
    into '/var/tmp/a_particular_folder'
}

But that does not work! It copies the files relative to the root project's path.

I've tried a lot of things:

  1. into new File('/var/temp/my_particular_folder') // creates relative to project root
  2. into file ('/var/temp/my_particular_folder') // again relative to project root
  3. into '/var/temp/my_particular_folder' // again relative to project root
  4. into '//var/temp/my_particular_folder' // Throws nullpointer
  5. into 'c:/var/temp/my_particular_folder' // works but only on windows.

Any clues anybody of how to copy into a filesystem folder relative to the root of the filesystem?

Edit: Using version 2.8

Upvotes: 1

Views: 2057

Answers (1)

Anup Puranik
Anup Puranik

Reputation: 165

Answering myself.

I managed to solve this problem by using:

into new File('/var/temp/my_particular_folder').absolutePath

Note the 'new File()' and then 'absolutePath' on it. Works on Windows, Linux, Mac.

Upvotes: 4

Related Questions