gradlebuild.gradlenewlinelf

Gradle line ending char for sourceSets


My build.gradle file contains the following:

sourceSets {
   main { output.resourcesDir = "build/app" }
}

This is working well, content of src/main/resources is correctly copied into build/app folder.

However, I have some resources (scripts) for which I need to force the line ending character. I need to always force an LF. In order word, need to be sure that we never have any CRLF.

Question: is it possible to filter resources included via a sourceSets?


Solution

  • Following works well:

    import org.apache.tools.ant.filters.FixCrLfFilter
    
    processResources {
        filesMatching('**/*.sh') {
            filter(FixCrLfFilter.class,
            eol:FixCrLfFilter.CrLf.newInstance("lf"))
        }
        filesMatching('**/*.properties') {
            filter(FixCrLfFilter.class,
            eol:FixCrLfFilter.CrLf.newInstance("lf"))
        }
        filesMatching('**/*.xml') {
            filter(FixCrLfFilter.class,
            eol:FixCrLfFilter.CrLf.newInstance("lf"))
        }
    }