How to preserve Java resources folder structure

I’m using Gradle 2.12

I have two resource folders that I include during test.

target/
   +---generated/
   |   +---WebContent/
   |   |   +---some files
   |   +---ProgramNames.properties
   +---WDR/
   |   +---Some folders which has files

excepted_target/
   +---generated/
   |   +---WebContent/
   |   |   +---some files
   |   +---ProgramNames.properties
   +---WDR/
   |   +---Some folders which has files

The problem is that the folders target and excepted_target are not preserved in resources/test. This is a problem because the two folders are used to compare one with the other. The folder that comes last in the build file overwrites the previous folder.

sourceSets {
    test {
        java.srcDirs = ['src']
        resources.srdDirs = ['conf', 'target', 'excepted_target']
    }
}

Are you trying to copy a set of folders an then want to see if that set matches against an expected set ?

If that is the case I would not copy the expected set (not make it part of resource dirs).

No that is not what i’m trying.
I want Gradle to add the three folders conf, target and expected_target to build/resources/test/. Not just the contents of the three folders.

THat is not the way processResources will work.

You could place all three folders uneath one other folders and rather add that to resources.srcDirs or you can add something like.

processTestResources {
  doLast {
    copy {
      from 'conf'
      from 'target'
      from 'expected_target'
      into sourceSets.test.resources.outputDir
    ]
  }
}

Thank you.

Is processTestResources not a task of type Copy? If so why wrapped into a doLast copy?

Yes, you are correct. I did not think about it that way. ProcessResources does indeed extend Copy. In addiiton my example code was still wrong as it would have dropped the folder names.

My first sugegstion of putting everything below a top folder would still work happily, and would be my suggestion. However if your folders are top-level, the following works (after having tested it).

processTestResources {
  from projectDir, {
    include 'conf/**'
    // etc.
}

All of the other stuff will get copied and you will get your folders you wanted.

1 Like