Sergei Ledvanov
Sergei Ledvanov

Reputation: 2251

How can I change the token format of ReplaceTokens filter in gradle?

I have tokens in the file in a bash format looking something like this:

PASSWORD=$PASSWORD

How can I change ReplaceTokens filter so that it would respect the bash format?

copy{ 
  into something
  from somethingelse
  filter(ReplaceTokens, tokens: [PASSWORD:'123456'])  
}

Upvotes: 0

Views: 1089

Answers (2)

Bruce Lowe
Bruce Lowe

Reputation: 6203

ReplaceTokens supports a begin and end token, so you could do this:

    filter( ReplaceTokens,
        beginToken : '$',
        endToken : '',
        tokens: [PASSWORD:'123456']
    )

Upvotes: 1

Sergei Ledvanov
Sergei Ledvanov

Reputation: 2251

The solution is to use expand property of a copy task:

https://docs.gradle.org/3.4/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:expand(java.util.Map)

task copyProductionConfig(type: Copy) {
  from 'source'
  include 'config.properties'
  into 'build/war/WEB-INF/config'
  expand([
    databaseHostname: 'db.company.com',
    version: versionId,
    buildNumber: (int)(Math.random() * 1000),
    date: new Date()
  ])
}

Upvotes: 0

Related Questions