Gradle 2.0加载java属性文件的正确方法?
在Gradle中,您可以通过以下方式从属性文件加载数据:
apply from: "version.properties"
从Gradle 2.0开始,这将生成一个警告:
"Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties."
在Gradle最新和最伟大的版本中,相同行为的规范手段是什么
当然,我可以通过定义一个helper方法来解决这个问题,但我很好奇是否有更简洁的方法
# 1 楼答案
从
gradle.properties
以外的属性文件加载数据的正确方法始终是使用Java的Properties
类:只有在所有属性值都是数字的情况下,通过
apply from: "version.properties"
加载属性才起作用(因为这样属性文件语法就变成了Groovy语法的一个子集)。1中已出现弃用警告。x(至少是去年的1.x版本)。2.0最终取消了在不使用def
或ext.
声明属性的情况下动态引入属性的功能,这解释了为什么它很难失败