How to create an empty fileTree?


(Horcrux7) #1

I want to init a source property of my task with an empty file tree. How can I do this?

task myBaseTask() {
    ext.source = fileTree()
 }

(Horcrux7) #2

I use now:

ext.source = fileTree{}

But this produce 2 warnings: fileTree(Closure) has been deprecated and is scheduled to be removed in Gradle 2.0. Use fileTree((Object){ baseDir }) to have the closure used as the file tree base directory.

and

Converting class java.util.Collections$EmptyMap to File using toString() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use java.io.File, java.lang.String, java.net.URL, or java.net.URI instead.

Do you have some other suggestions?


#3

A FileTree must have a base directory. If you know what the base directory will be (or should default to), then you can use

ext.source = fileTree(<baseDir>)

If you don’t know the directory, then I’d need to know your use case before I could suggest a better option.


(Horcrux7) #4

The use case is to add the directories/files later in other tasks in other files.

apply from: "/gradle/base.gradle"
  task xyz() {
    myBaseTask.source += fileTree(....)
 }
  task abc() {
    myBaseTask.source += fileTree(....)
 }

#5

So do you know the base directory of “source”? Or does the user need to configure it explicitly?


(Horcrux7) #6

No, I does not know one of the base directories.

It is like the copy task. The copy task self does not know the base directory. Only with a later using the base directory will be set.


#7

Well I don’t know how to achieve that. Maybe somebody else can help out?


(Horcrux7) #8

Ok, I have find a solution that does not produce any warnings.

ext.source = fileTree( 'directory does not exists' )

But it is very ugly.


Re: How to create an empty fileTree?