1

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?

4

1 回答 1

2

以下效果很好:

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"))
    }
}
于 2017-08-08T07:48:12.667 回答