如何连接Gradle中的多个文件? [英] How do I concatenate multiple files in Gradle?

查看:167
本文介绍了如何连接Gradle中的多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有简单的方法将多个文本文件连接成一个Gradle中的文件?构建脚本应该如下所示:

  FileCollection jsDeps = files(
'file1.js',
'file2.js'
//这里的其他文件


任务连接<< {
//连接文件到file.js
}

我是使用Gradle 2.3。

解决方案

 (新文件('test.js'))。文本文件('test1.js')。getText()+文件('test2.js')。getText()

更新:

适用于收藏。 > (new File('test.js'))。text = files('test1.js','test2.js')。collect {it.getText()}。join(\ n)


Is there an easy way to concatenate multiple text files into a single one in Gradle? The build script should look something like this:

FileCollection jsDeps = files(
   'file1.js',
   'file2.js'
   // other files here
)

task concatenate << {
   // concatenate the files to file.js
}

I am using Gradle 2.3.

解决方案

(new File('test.js')).text = file('test1.js').getText() + file('test2.js').getText()

UPDATE:

For collections.

(new File('test.js')).text = files('test1.js', 'test2.js').collect{it.getText()}.join("\n")

这篇关于如何连接Gradle中的多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆