I want to replace a @VERSION@
token in a java source file with a version before building (Gradle is my build system of choice).
In my current script a
I faced the same problem. And I was unable to find working solution. None of the examples I found worked. I believe it might to a fact, that I am new to Gradle and those examples omit some obvious pieces of code. So I looked into Gradle and found my own solution, that I'd like to share:
import org.apache.tools.ant.filters.ReplaceTokens
// Change compiler source directory
sourceSets {
main {
java {
srcDirs = ['build/src/main/java']
}
}
}
// Prepare sources for compilation
task prepareSources(type: Copy) {
from('src/main/java')
into('build/src/main/java')
filter(ReplaceTokens, tokens: [pluginVersion: version])
}
// Prepare sources, before compile
compileJava {
dependsOn prepareSources
}