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

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

问题描述

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

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?

推荐答案

您可以使用 ant.propertyfile 任务:

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天全站免登陆