gradle groovy 读取 properties 文件

小咪咪 2023-01-05 12:06 246阅读 0赞

build.gradle

  1. task readProperties {
  2. def localProperties = new Properties()
  3. def dis = null
  4. try {
  5. def localFile = rootProject.file('app.properties')
  6. if (localFile.exists()) {
  7. dis = localFile.newDataInputStream();
  8. localProperties.load(dis)
  9. }
  10. } catch (Exception ignored) {
  11. println ignored
  12. } finally {
  13. // 一定要关闭输入流 否则文件会一直被java占用
  14. if (dis != null) {
  15. dis.close()
  16. }
  17. }
  18. def version = localProperties.getProperty("version")
  19. String name = localProperties.getProperty("name")
  20. println version
  21. println name
  22. }

执行命令:

  1. gradle -q readProperties

发表评论

表情:
评论列表 (有 0 条评论,246人围观)

还没有评论,来说两句吧...

相关阅读

    相关 GradleGroovy

    1. Groovy 简介 在某种程度上,Groovy 可以被视为 Java 的一种脚本化改良版,Groovy 也是运行在 JVM 上,它可以很好地与 Java 代码及 其

    相关 gradlegroovy

    我是学习一篇CSDN博客,然后总结的这篇笔记,直接看这篇笔记可能会云里雾里,所以请先参考原文:[http://blog.csdn.net/innost/article/deta