Having trouble with Copy task with a filetree preserving directories

[I’m using gradle 1.4] and running into behavior that does not meet my expectations and not sure if its a bug or if my expectations are wrong.

I’m stripped this down to a dummy test case:

I have a project with a directory like such:

build.gradle conf/file1.txt conf/inner/file2.txt

And my gradle looks like this:

configurations {
  conf
}
  dependencies {
  conf fileTree(dir: 'conf')
}
  task copyDirect(type: Copy) {
  from fileTree('conf')
  into "${project.buildDir}/conf"
}
  task copyFromConfiguration(type: Copy) {
  from configurations.conf.getAsFileTree()
  into "${project.buildDir}/conf"
}

If I run ‘gradle copyDirect’, my build directory looks like this:

% find build -type f
build/conf/file1.txt
build/conf/inner/file2.txt

But, if I I run the copyFromConfiguration task, it looks like this:

build/conf/file1.txt
build/conf/file2.txt

Essentially it was my understanding that I could call getAsFileTree() on the ‘conf’ configuration file collection and it would preserve the directory structure, but as you can see my ‘inner’ directory has disappeared.

Is there something I’m missing or misunderstanding here, or is this a bug?

Thanks.

Doug

It works as designed. Adding a file tree to a configuration flattens it. ‘getAsFileTree’ isn’t the inverse of flattening. From the Javadoc:

Converts this collection to a {@link FileTree}. Generally, for each file in this collection, the resulting file tree will contain the source file at the root of the tree. For each directory in this collection, the resulting file tree will contain all the files under the source directory.

Thanks, Peter. Is this the only behavior acceptable for fileTree’s added to a configuration, or is there a way to override this behavior. I guessing its the former, but I’ll do my best mine through the source code and see if I can grok what’s going on.

There’s no way to override this. A (resolved) configuration is a flat class path and has no concept of hierarchy. If you explained the bigger picture, we might be able to find a solution.