【问题标题】:Gradle: save property fileGradle:保存属性文件
【发布时间】:2015-06-19 23:05:21
【问题描述】:

我在我的项目中使用 NewRelic。它需要带有应用程序令牌的 newrelic.properties 文件。我需要使用不同的令牌创建几个构建。在用于生成属性的 gradle 中,我使用下一个 sn-p:

Properties props = new Properties()
props.setProperty("com.newrelic.application_token","MYTOKEN")

如何将其保存到我的应用文件夹?我需要根文件夹中带有文本“com.newrelic.application_token=MYTOKEN”的“newrelic.properties”文件。

【问题讨论】:

    标签: android gradle properties-file


    【解决方案1】:

    您可以使用 -P 标志来指示构建配置文件:

    gradle clean build -Pprofile=dev
    

    然后在构建脚本中使用它:

    File propsFile = new File('/libs/newrelic.properties')
    if (project.getProperty('profile') == "dev") {
        println "Target environment: $profile"
        Properties props = new Properties()
        props.setProperty("com.newrelic.application_token","DEV_TOKEN")
        props.store(propsFile.newWriter(), null)
    }
    

    【讨论】:

      【解决方案2】:

      我用更简单的方法:

      ant.propertyfile(file: "newrelic.properties") {
                  entry( key: "com.newrelic.application_token", value: "AA165ad2e3e518***********************sd2")
              }
      

      从此: How can I transform a .properties file during a Gradle build?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-12
        相关资源
        最近更新 更多