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


(Anirban Roy) #1

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


(Mark Vieira) #2

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")])
        }
    }
}

(Anirban Roy) #3

@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!