How to copy resource files in classes folder with gradle?

烂漫一生 提交于 2019-12-22 06:56:55

问题


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:


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.



来源:https://stackoverflow.com/questions/42552581/how-to-copy-resource-files-in-classes-folder-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!