抑制Gradle可执行任务中的交互输出

当命令更新文本时,一些Gradle Exec任务会产生过多的输出。

当从terminal运行时,这些命令会产生几行输出,这些输出将被更新。

当从Gradle中运行时,每次更新时都会产生一个新的输出行,例如:

dockerbuild设

task dockerBuild(type: Exec) { commandLine 'docker', 'build', '-t', 'foo', '.' } 

运行时产生:

 Sending build context to Docker daemon 557.1 kB Sending build context to Docker daemon 1.114 MB Sending build context to Docker daemon 1.646 MB Sending build context to Docker daemon 2.17 MB Sending build context to Docker daemon 2.72 MB Sending build context to Docker daemon 3.277 MB Sending build context to Docker daemon 3.834 MB Sending build context to Docker daemon 4.391 MB ... hundreds more lines ... 

wget

 task fetchData(type: Exec) { commandLine 'wget', 'http://example.org/some/large/file' } 

当运行输出时:

 HTTP request sent, awaiting response... 200 OK Length: 209715200 (200M) [application/zip] Saving to: '200MB.zip' 0K .......... .......... .......... .......... .......... 0% 5.02M 40s 50K .......... .......... .......... .......... .......... 0% 6.34M 36s 100K .......... .......... .......... .......... .......... 0% 6.68M 34s 150K .......... .......... .......... .......... .......... 0% 6.42M 33s 200K .......... .......... .......... .......... .......... 0% 6.41M 33s 250K .......... .......... .......... .......... .......... 0% 7.12M 32s ... thousands more lines ... 

这是什么我可以修复从Gradle内(例如要求它在非交互模式下执行命令),还是个别的应用程序提供禁用这种输出的标志?

从Exec DSL文档中 ,您可以将可执行文件的输出redirect到您自己的stream。

 //store the output instead of printing to the console: standardOutput = new ByteArrayOutputStream() 

您也可以select性地redirect错误stream,以保持完全安静,但通过保持完好无损,您将在gradle日志中看到任何退出错误。