2016-01-13 66 views
2

当命令更新文本时,某些Gradle Exec任务会产生过多的输出。抑制Gradle可执行任务中的交互输出

从终端运行时,这些命令会产生几行输出,这些输出会在适当位置进行更新。

当从内摇篮运行,它们会产生新的输出线每次的东西被更新,如:

搬运工建立

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 ... 

这是什么我可以从内部摇篮修复(如请求它以非交互模式执行命令),还是由个别应用程序提供禁用此类输出的标志?

回答

1

Exec DSL documentation开始,您可以将可执行文件的输出重定向到您自己的流。

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

你可以选择性地也重定向错误流,以保持它完全安静,但离开它的完整,你会看到在日志的gradle出任何错误。