我正在使用heroku的config var插件(请参阅https://devcenter.heroku.com/articles/config-vars).
它允许我使用.env文件,我不推送源代码控制来定义heroku环境.
因此,当我在heroku上时,我可以通过System.properties访问合理的信息.
在开发中,我想从这个文件中读取,所以如果它在我的类路径上是最好的.
.env文件是我项目的根目录,所以我不能使用这样的东西:
sourceSets {
main {
resources {
srcDirs = ['src/main/resources', '/']
}
}
}
Run Code Online (Sandbox Code Playgroud)
将单个文件包含到gradle资源中的最简单方法是什么?
将之前的答案与其他网站的其他提示合并后,我提出了以下解决方案:
sourceSets {
specRes {
resources {
srcDir 'extra-dir'
include 'extrafiles/or-just-one-file.*'
}
}
main.resources {
srcDir 'src/standard/resources'
srcDir specRes.resources
}
}
processResources {
rename 'some.file', 'META-INF/possible-way-to-rename.txt'
}
Run Code Online (Sandbox Code Playgroud)
我仍然想知道是否有更好的方法。
较早的答案似乎比我期望的要复杂,因此我在gradle论坛上进行了询问,并得到了gradle核心开发人员之一的Sterling Green的答复。
他建议processResources
直接配置
processResources {
from(".env")
}
Run Code Online (Sandbox Code Playgroud)
他还提到直接将项目根目录作为输入内容可能不是一个好主意。
我最终做的是将项目根目录添加为资源文件夹,仅包含我感兴趣的文件:
sourceSets.main.resources { srcDir file('.') include '.env' }
Run Code Online (Sandbox Code Playgroud)
似乎可以做到这一点。我想知道这是否是最好的解决方案
归档时间: |
|
查看次数: |
3686 次 |
最近记录: |