【问题标题】:Suppressing interactive output in Gradle exec tasks抑制 Gradle exec 任务中的交互式输出
【发布时间】:2016-01-13 12:07:08
【问题描述】:

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

当从终端运行时,这些命令会产生几行更新的输出。

当从 Gradle 中运行时,它们会在每次更新某些内容时产生一个新的输出行,例如:

docker 构建

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 中解决的任何问题(例如,要求它在非交互模式下执行命令),还是由单个应用程序提供标志以禁用此类输出?

【问题讨论】:

    标签: gradle docker


    【解决方案1】:

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

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

    您还可以选择重定向错误流以使其完全安静,但如果保持原样,您将在 gradle 日志中看到任何退出错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 2011-09-13
      • 1970-01-01
      相关资源
      最近更新 更多