gradle groovy 读取 properties 文件
build.gradle
task readProperties {
def localProperties = new Properties()
def dis = null
try {
def localFile = rootProject.file('app.properties')
if (localFile.exists()) {
dis = localFile.newDataInputStream();
localProperties.load(dis)
}
} catch (Exception ignored) {
println ignored
} finally {
// 一定要关闭输入流 否则文件会一直被java占用
if (dis != null) {
dis.close()
}
}
def version = localProperties.getProperty("version")
String name = localProperties.getProperty("name")
println version
println name
}
执行命令:
gradle -q readProperties
还没有评论,来说两句吧...