Gradle - 将单个文件添加到JAR

And*_*ndi 14 jar file task include gradle

我在项目的根目录中有"license.txt"文件.在jar-task中,我想将此文件添加到JAR文件的(根文件夹)中.

我试过了

jar {
  from '.' include 'license.txt'
}
Run Code Online (Sandbox Code Playgroud)

但这会替换其他内容(.class文件)而不是添加文件.我不想将license.txt添加到resources文件夹,因为我不想仅仅因为构建工具而改变我的项目结构.

谁可以帮忙?谢谢!

Pet*_*ser 16

要添加单个文件,您只需执行以下操作:

jar {
    from "license.txt"
}
Run Code Online (Sandbox Code Playgroud)

如果includefrom通过将其括在花括号中来限制您的解决方案,那么您的解决方案也应该有效.


小智 7

如果要添加多个文件,可以执行以下操作:

jar{
    from{
        ["aaa.txt","bbb.txt"]
    }
}
Run Code Online (Sandbox Code Playgroud)