Need a workable copyspec out of the parent directory

Continuing the discussion from Establishing task dependencies in a plugin:

OK, this one is still kicking my butt. Not sure how to handle it.

Another case of making hard things easy but easy things hard.

Conceptually my file spec is simple:

every rpm file under the parent project directory.

First of all I can’t specify something like project.parent.projectDir in a copy spec because the closure refuses to evaluate it and I get an error like this:

Could not find method parentDir() for arguments [com.att.voicetone.gradle.plugins.BundlerTask$_applyBundleDefinition_closure1$_closure4@3484f140] on task ':bundle:bundle'.

So that doesn’t work, or at least I don’t know the groovy trick to make it work.

I’ve also tried

        def tarSpec = project.copySpec { 
            include "../**/*.rpm"
        }
     
  
        into '/'
        with tarSpec

This does not produce errors but the task is in an UP-TO-DATE state that cannot be changed even with outputs.upToDateWhen { false }

How’s about

def spec = copySpec {
   from ".."
   include "**/*.rpm" 
}
with spec
into "/" 

PURR-fect!

Thanks so much.

I hadn’t found fileTree.

and now I see you changed it …

Either way would’ve worked. You asked for a copySpec so I changed original fileTree solution to a copySpec.

Yup, they both work and I include them both again for completeness.

		def rpmTree = project.fileTree("..").matching { 
			include "**/*.rpm"  
		}
		from rpmTree
		into "/"

		def spec = copySpec {
			from ".."
			include "**/*.rpm"
		}
		with spec
		into "/"

What was leading me astray was something very similar that I tried and failed with.

            def spec = copySpec {
                from "../"
                include "**/*.rpm"
            }
            with spec
            into "/

For some reason I thought I needed a slash after the dot dot. No good. It brings the following less than intuitive error message:

A problem occurred configuring project ‘:bundle’.

Could not find method copySpec() for arguments [com.att.voicetone.gradle.plugins.BundlerTask$_applyBundleDefinition_closure2@4350ef1b] on task ‘:bundle:bundle’.

Thanks for your help.

and if I wanted the output flattened, that is, all the rpms at the root level of the tar, not replicating their locations in the input tree? Is there a simple flattening transformer for copySpecs? I didn’t find one immediately obvious.

You could effectively flatten the fileTree using
from rpmTree.files

Thanks again, that’s exactly what I was looking for.

My efforts led me down a wrong path attempting to use rename, and I think that method is not well documented. I will open a new issue on that.