markovuksanovic
markovuksanovic

Reputation: 15906

Gradle replace token in a file during build process

I have a web application and I use gradle to build it. In one of the xml files in WEB-INF folder (src/main/webapp/WEB-INF/my.xml) I have a piece of file that needs replacing.

<system-properties>
    <property name="clientId" value="@clientId@" />
</system-properties>

When I try to replace the token with some value using:

processResources{
  filter(ReplaceTokens, tokens:['clientId': 'test'])
}

Than when I run gradle build the token in the output file (./build/exploded-app/WEB-INF/my.xml) is not replaced. I was wondering which is the correct way to do this?

Upvotes: 6

Views: 10574

Answers (1)

atschabu
atschabu

Reputation: 91

The problem is that you are configuring the wrong task. processResources only copies files from src/main/resources (or whatever else you define in the main sourceSet as resource), while it is task war which copies / zips your my.xml.

war {
  filter(ReplaceTokens, tokens:['clientId': 'test'])
}

Upvotes: 6

Related Questions