0

I use NewRelic in my project. It needs newrelic.properties file with application token. I need to create several builds with different token. In gradle for genereting properties I use next snippet:

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

How can I save it to my app folder? I need "newrelic.properties" file with text "com.newrelic.application_token=MYTOKEN" in root folder.

ArturNFR
  • 89
  • 7

2 Answers2

2

You can use -P flag to indicate build profile:

gradle clean build -Pprofile=dev

Then use it in build script:

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)
}
cslysy
  • 810
  • 7
  • 11
1

I use more simple way:

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

from this: How can I transform a .properties file during a Gradle build?

Community
  • 1
  • 1
ArturNFR
  • 89
  • 7