Gradle replace token in a file during build proces

2019-05-01 21:21发布

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?

1条回答
劳资没心,怎么记你
2楼-- · 2019-05-01 21:37

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'])
}
查看更多
登录 后发表回答