How do you properly reference files in parent directories outside of gradle project

I’m trying to get the following copy task to work, but it keeps saying its UP-TO-DATE

task patchContainer(type: Copy) {
   from files(new File("${projectDir}/../../../common/shared/"));
  into "${containerHome}/bin"
  task check << {
   def src = new File("${projectDir}/../../../common/shared/")
  def tgt = new File("${containerHome}/bin/")
  println "src ${src.exists()}"
  println "tgt ${tgt.exists()}"
  % gradle -a patchContainer doubleCheck
:webapp:app:patchContainer UP-TO-DATE
src true
tgt false

Seems I can’t figure out the magic to properly pass a FileCollection that contains a file with paths containing “…” to the Copy tasks’s from property.

Agreed its not the most idea approach to begin with, but I’m refactoring a legacy build right now and need to keep both ant and gradle builds working functionally till we’re ready to switch exclusively to gradle at with point I’ll be free to move source files around more freely.

Any tips would be greatly appreciated.

Sounds like you have a multi-module project setup. Given that you have a two-level module hierarchy you could reference specific modules like this:

def src = new File("${project(':common:shared').projectDir}/")

Thanks for the response.

I do have a multi-module project setup. Unfortunately, ‘:common:shared’ is not part of a my multi project build.

I’m trying to access files somewhere within a directory which is peer to the root directory of my project build.

So my directory structure looks like this:


shared/ myapp/ (my top-level gradle)





build.gradle -< It’s in here I need to get a handle on …/…/…/common/shared/

As I said, the layout is not idea and moving to gradle is part of a longer term effort to clean alot of this up and start adopting some modern build best practices, but in the meantime, I’m just trying to take some baby steps. Seems there is the ability to do things like this in ant, so I would assume gradle would make it possible too. I’m away from my laptop now, but that got me thinking that I’ll look to see how we do this in ant and maybe that will provide me with some inspiration. Thanks again.

I ran into a similar problem with milestone-6. I developed the following gradle config that worked fine in milestone-3:

repositories {
          flatDir name: 'externalJarProject',
             dirs: "${projectDir}/../gov.noaa.datadelivery.plugin_independent_jars"

When I uploadedArchives to “externalJarProject”, it properly installed the jars in the directory I specify above. However, in milestone-6, this seems to be broken. Now it installs the jars in gov.noaa.datadelivery.plugin_independent_jars