如何使用gradle复制类文件夹中的资源文件? [英] How to copy resource files in classes folder with gradle?

查看:856
本文介绍了如何使用gradle复制类文件夹中的资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境



我使用需要字节码检测的第三方库。执行字节码检测的工具需要一些描述文件,这些文件必须与编译的.class文件一样处于相同的文件夹结构中。这些文件只在编译时才需要。



问题



将所有文件(资源和类)暂时放在同一个文件夹中,然后从该文件夹创建一个jar文件。但是在组装jar之前,似乎gradle有两个不同的资源和类文件位置。
就像之前提到的那样,代码工具的第三方工具需要描述文件与类文件一样处于相同的文件夹结构中。



问题



简单地说:我该如何解决这个问题?

想法


  1. 将描述文件放入 src / main / java 中。不是很干净,但可能是一个解决方案。遗憾的是,gradle忽略了这些文件。我试图以某种方式包含它们,但没有得到它的工作。

  2. 暂时将描述文件复制到正确的位置。也不是非常干净的方式您可以通过以下方式重定向资源输出目录:


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

    ,那么包含类文件( build / classes / main )的文件夹也会包含您的资源。


    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

    解决方案

    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.

    这篇关于如何使用gradle复制类文件夹中的资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆