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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With