如何在Gradle构建期间转换.properties文件? [英] How can I transform a .properties file during a Gradle build?

查看:163
本文介绍了如何在Gradle构建期间转换.properties文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Gradle中部署任务的一部分,我希望将 foo.properties 中的属性值更改为生产数据库而不是开发数据库。



我不想直接替换整个文件,因为它很大,而且意味着我们必须维护两个不同的版本,这些版本只在一行上有所不同。 / p>

完成此操作的最佳方法是什么?

解决方案

使用ant.propertyfile任务:

  ant.propertyfile(
file:myfile.properties){
入口(key:propertyName,value:propertyValue)
入口(key:anotherProperty,操作:del)
}


As part of a deploy task in Gradle, I want to change the value of a property in foo.properties to point to a production database instead of a development database.

I'd rather not replace the whole file outright, as it's rather large and it means we would have to maintain two separate versions that only differ on a single line.

What is the best way to accomplish this?

解决方案

You can use the ant.propertyfile task:

    ant.propertyfile(
        file: "myfile.properties") {
        entry( key: "propertyName", value: "propertyValue")
        entry( key: "anotherProperty", operation: "del")
    }

这篇关于如何在Gradle构建期间转换.properties文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆