Gradle replace token in a file during build process

落爺英雄遲暮 提交于 2019-12-07 04:01:23

问题


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:


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'])
}


来源:https://stackoverflow.com/questions/21247193/gradle-replace-token-in-a-file-during-build-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!