如何在任务中对源文件进行排序?

时间:2013-10-03 12:58:03

标签: sorting gradle

我有来自gradle-js-plugin的combineJs任务:

combineJs {

    def jsFiles = fileTree(dir: "/lib/", include: "jquery.js")
    jsFiles += fileTree(dir: "/lib/plugins", include: "*.js") //.sort()
    jsFiles += fileTree(dir: "/lib/", include: "underscore.js")

    source = jsFiles
    dest = file("/js/all.js")
}

我想按照自然顺序对插件进行排序,因为当它在unix上组合时,它的顺序与Windows不同。

我该怎么办?我尝试了很多不同的方法。

例如:

combineJs {

    def jsFiles = fileTree(dir: "/lib/", include: "jquery.js")
    jsFiles += fileTree(dir: "/lib/plugins", include: "*.js") //.sort()
    jsFiles += fileTree(dir: "/lib/", include: "underscore.js")

    source = jsFiles.collect { File file -> relativePath(file) }.sort().each { fileTree(it) }
    dest = file("/js/all.js")
}

1 个答案:

答案 0 :(得分:1)

这个怎么样:

List<File> ll = new ArrayList<>(jsFiles.getFiles())
Collections.sort(ll)