【问题标题】:Gradle: Output file not up to date if parsed from standardOutputGradle:如果从标准输出解析输出文件不是最新的
【发布时间】:2012-11-01 06:43:48
【问题描述】:

我遇到的问题是 gradle 中的 Exec 任务在最新检查输出文件是否从标准输出中捕获时出现问题。

我已尽量简化示例:

task printToOutputFile(type: Exec) {
    inputs.file file("file1") // not relevant for this example
    outputs.file file("file2")

    commandLine = ["echo", "1234"]
    standardOutput = new FileOutputStream("file2")
}

重新运行此任务时,我希望它是最新的,但事实并非如此。

当使用标准输出作为输出时,如何使 UP-TO-DATE 检查工作?

我尝试过的:
在 doLast 块中关闭和/或刷新流。

【问题讨论】:

    标签: gradle


    【解决方案1】:

    问题是,那行

    standardOutput = new FileOutputStream("file2")
    

    更改 file2 的 lastModified 属性。要使最新检查正常工作,您必须将此分配移至执行阶段。您可以通过将此分配放在 doFirst 块中来做到这一点。以下 sn-p 应该可以解决问题:

    task printToOutputFile(type: Exec) {
        inputs.file file("file1") // not relevant for this example
        outputs.file file("file2")
    
        commandLine = ["echo", "1234"]
    
        doFirst{
            standardOutput = new FileOutputStream("file2")
        }
    }
    

    干杯,

    勒内

    【讨论】:

    • 谢谢 :) 这实际上是非常合乎逻辑的。我再一次没有考虑 gradles 不同的阶段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2011-01-08
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    相关资源
    最近更新 更多