Gradle and the FixCrLfFilter

I stumbled quite a bit configuring a FixCrLfFilter in the CopySpec of a Gradle build file… so I thought it would be best to show how it’s done…

The documentation in the user-guide is still a little bit lacking at the time of this writing.

So here it is: a fully configured FixCrLfFilter with all options defined instead of depending on default values!

into('bin') {
    from("${projectDir}/src/bin") {
        include 'lilith'
        fileMode = 0755
            eol: FixCrLfFilter.CrLf.newInstance('lf'),
            tab: FixCrLfFilter.AddAsisRemove.newInstance('asis'),
            eof: FixCrLfFilter.AddAsisRemove.newInstance('remove'),
            fixlast: true)

This sets the file permissions to rwxr-xr-x (actually unrelated to the FixCrLfFilter), converts the end-of-line characters to unix style (i.e. only \n), leaves tabs and spaces alone, removes end-of-file characters if any are contained in the file and adds a newline to the last line of the file if it was previously missing.

Hope that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *