Copy ReplaceTokens filter not working

I am trying to update a properties file located located at ‘src/main/resources/path/to/package/build.properties’ every time I run the build task. What I have so far is:

task updateVersion(type: Copy) << {

ext.versions = project.version.split("\.")

from ‘src/main/resources/path/to/my/properties’

into getDestDir()

filter(ReplaceTokens, tokens: [major: versions[0], minor: versions[1], revision: versions[2]])

}

build.dependsOn updateVersion

All that is in my properties file is:

build.major=@major@

build.minor=@minor@

build.revision=@revision@

Am I getting the destination directory wrong? I tried specifying the specific location for the ‘into’ field, but that didn’t work either. I want to be able to let Gradle decide where my source files’ destination should be.

you have to get rid of the “<<” in your task definition. At the momen, you’re adding a task action instead of configuring it.

cheers, René

So, I was able to get it working, but not with ‘getDestDir()’. I can’t figure out how to let Gradle decide where to put it for me, or if it is even possible to specify that.

task updateVersion(type: Copy) {

ext.versions = project.version.split("\.")

from ‘src/main/resources/path/to/my/properties’

into ‘build/resources/main/path/to/my/properties’

filter(ReplaceTokens, tokens: [major: versions[0], minor: versions[1], revision: versions[2]])

}

build.dependsOn updateVersion

jar.dependsOn updateVersion

I don’t understand the question, as you are already using ‘into’ to determine the destination. Maybe your ‘getDestDir()’ method is computing the wrong value. By the way, to do resource filtering you’d just have to configure the ‘processResources’ task, which is also of type ‘Copy’.