How to copy resource files in classes folder with gradle?

9.7k Views Asked by At

Enviroment

I am using a third party lib which requires bytecode instrumentation. The tool which does the bytecode instrumentation requires some description files and those files have to be in the same folder structure like the compiled .class files. Those files are only necessary at compiletime.

Problem

I thought gradle would place all files (resource and class) temporarily within the same folder and then create a jar from that folder. But it seems that gradle have two different places for resources and class files before assembling a jar. Like mentioned before the third party tool for code instrumentation requires the description files in the same folderstructure like the class files.

Question

Simply: How can I solve this Problem?

Ideas

  1. Place the description files with in src/main/java. Not very "clean" but could be a solution. Sadly gradle ignores those files. I tried to include them somehow but didn't get it working yet.
  2. Temporarily copy the description files to the right place. Also not a very "clean" way
1

There are 1 best solutions below

2
On BEST ANSWER

You can redirect the resources output dir by:

sourceSets {
  main {
    output.resourcesDir = "build/classes/main"
  }
  test {
    output.resourcesDir = "build/classes/test"
  }
}

then the folder with class files (build/classes/main) will also contain your resources.