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
You only need to replace @VERSION@
tokens before releasing your software to the public. Here I defined a task compileForRelease
that accomplishes it:
import org.apache.tools.ant.filters.ReplaceTokens
task sourcesForRelease(type: Copy) {
from 'src/main/java'
into 'build/adjustedSrc'
filter(ReplaceTokens, tokens: [VERSION: '2.3.1'])
}
task compileForRelease(type: JavaCompile, dependsOn: sourcesForRelease) {
source = sourcesForRelease.destinationDir
classpath = sourceSets.main.compileClasspath
destinationDir = file('build/adjustedClasses')
}
I don't recommend messing with standard tasks defined by the Java plugin because that would add unnecessary overhead to each and every build.