Multi-line strings in gradle.properties

John Chrysostom :

I'm developing an Android app, and I don't want to put creds under source control. I'm defining some creds in my gradle.properties file, like so:

user="bob"
pass="123"

I then import them in my build.gradle file, like so:

buildConfigField('String', "user", user)
resValue('string', "user", user)

Then, I can access them from Java as if they were a normal String resource.

Unfortunately, I also need to include a multi-line string in my gradle.properties file. I've tried the following:

long_string="this is
a multi-line string"

However, when I try to build my project, I get an error message that I have an unclosed string literal.

The docs for gradle.properties don't seem to mention anything about multi-line string formatting.

Is what I want to do possible?

BlackHatSamurai :

Yes, what you want to do is possible. You have a couple options:

You can do something like:

  long_string = "this is" +
      "a multi-line string"

Or, you can do:

def startingAndEndingWithANewline = '''
       line one
       line two
       line three
    '''

Gradle is built on Groovy, so you can just reference the Groovy docs for things like this.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=140440&siteId=1