How to exclude a file from being processed by ProcessResource task?

Hi Experts,

I am trying to exclude a binary file from being processed by processResource task. Below is my code in build.gradle:

processResources {
    exclude('src/main/resources/com/mycompany/myapp/datafile/*.dat')
    it.dependsOn filterFiles
    filter(ReplaceTokens, tokens: [version: project.version, date: new Date().format("yyyy-MM-dd HH:mm")])
}

Here I dont want the filter(ReplaceTokens…) to run on the files from ‘src/main/resources/com/mycompany/myapp/datafile/*.dat’. But this does not work and the process corrupts the file. Please help.

Thanks,
Roy

I’d apply the filter conditionally instead to those files which are applicable.

processResources {
    eachFile { details -> 
        if (details.name.endsWith('.txt')) { // or whatever pattern/criteria is appropriate
            details.filter(ReplaceTokens, tokens: [version: project.version, date: new Date().format("yyyy-MM-dd HH:mm")])
        }
    }
}

@mark_vieira Superb!! you rule boss… I was trying to do something like this but could not do it since I am newbie. I just used if (!details.name.endsWith(‘.dat’)) (not ending with .dat) :slight_smile:

Thanks again!

Great tip! After some other searches I found another trick:

processResources {
     filesNotMatching("**/*.dat") {
         expand(
                 'project': ['version': project.version],
                 'build': ['timestamp': new Date().format('dd/MM/yyyy HH:mm')]
         )
     }
 }