How is a token replaced in a file for a Gradle build product?

感情迁移 提交于 2020-06-26 06:55:12

问题


I have a normal buildscript for Gradle set up, and one thing I want to do is have the version of my build specified. This is the code I've set up to replace the version token in my main Java source file:

import org.apache.tools.ant.filters.ReplaceTokens

processResources {
    from (sourceSets.main.java) {
        include 'T145/myproj/Main.java'
        filter(ReplaceTokens, tokens: ['@VERSION@' : project.version])
    }
}

However it doesn't work. I tried using the replace function, but that didn't prove to be a success either. My Main.java has a public variable VERSION that equals @VERSION@, and that is what I want to be replaced.


回答1:


Based on what I'm seeing in the Gradle manual example of ReplaceTokens, you want to get rid of the @'s in your filter line, so that it reads:

filter(ReplaceTokens, tokens: [VERSION : project.version])

Gradle assumes that the token it's looking for has the @'s delimiting it already, so it is trying to replace @@VERSION@@ instead of @VERSION@, like you want.



来源:https://stackoverflow.com/questions/30627918/how-is-a-token-replaced-in-a-file-for-a-gradle-build-product

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