Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle replace token in a file during build process

Tags:

build.gradle

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?

like image 825
markovuksanovic Avatar asked Jan 21 '14 00:01

markovuksanovic


1 Answers

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'])
}
like image 144
atschabu Avatar answered Nov 18 '22 07:11

atschabu