Copyspec of tar task includes unspecified files with out of source tree execution

My understanding of CopySpec include is that it includes only what it is told to include. But in this example it includes too much.

I have three trees: source, build and execution.

The source tree (~/src) contains the build file:

def cwd = System.getProperty("user.dir")
def txtFiles = project.copySpec {
  include '**/*.txt'
}
task archivePoems(type: Tar) {
  baseName = "foo"
  includeEmptyDirs = false
  destinationDir = file('build')
  compression = Compression.GZIP
  from(cwd) {
    with txtFiles
    into('build')
  }
}

The execution tree contains some files produced by an external process:

'-- poems
    |-- a
    |
 '-- b
    |
     '-- c
    |
         '-- bad.ext
    |-- life.txt
    |-- not_a_poem.bad
    |
 '-- bad
    '-- others

Create it with:

mkdir /tmp/$USER
cd /tmp/$USER
mkdir -p poems/a/b/c poems/not_a_poem.bad poems/others
touch poems/a/b/c/bad.ext poems/not_a_poem.bad/bad poems/life.txt

Now run gradle from the execution path:

cd /tmp/$USER
gradle -b ~/src/build.gradle archivePoems

The destinationDir contains a foo.tgz file with way too many files:

$ tar tvfz ~/src/build/foo.tgz
drwxr-xr-x 0/0
             0 2015-03-03 11:31 build/
drwxrwxr-x 0/0
             0 2015-03-03 11:29 build/poems/
-rw-rw-r-- 0/0
             0 2015-03-03 11:29 build/poems/life.txt
drwxrwxr-x 0/0
             0 2015-03-03 11:29 build/poems/a/
drwxrwxr-x 0/0
             0 2015-03-03 11:29 build/poems/a/b/
drwxrwxr-x 0/0
             0 2015-03-03 11:29 build/poems/a/b/c/
-rw-rw-r-- 0/0
             0 2015-03-03 11:29 build/poems/a/b/c/bad.ext
drwxrwxr-x 0/0
             0 2015-03-03 11:29 build/poems/not_a_poem.bad/
-rw-rw-r-- 0/0
             0 2015-03-03 11:29 build/poems/not_a_poem.bad/bad

The only file expected is the life.txt (and its path), it’s the only file matching the ‘’‘include ‘**/*.txt’’’’ pattern.

The path to the execution tree changes at every build, I don’t want to hardcode that in the gradle.build file.

How do I debug this? Does gradle support out of source tree execution? What’s the point of -b?

Now I’m working on making it standalone and am frustrated at the extra steps involved. I have to install the plugin ahead of time, then run the code that executes it. What was a one step process is now a two step process, which makes development more laborious.

_______________________ aliii