Как спросить Gradle, если конкретный ввод не актуален - PullRequest
0 голосов
/ 27 мая 2018

Есть ли способ в Gradle сделать что-то подобное?

task printIsSpecificInputUpToDate() {

    inputs.property("file1", file("file1.log"))
    inputs.property("file2", findProperty("file2.log"))
    outputs.file(file("file3.log"))

    // if one or more inputs is not up to date
    doLast {
        // find out if file1 is actually the input out of date
        // NOTE: pseudo-code!
        if (inputs.get("file1").isUpToDate()) {
            onlyProcessFile2()
        } else {
            processFile1AndFile2()
        }
    }
}

Если нет, значит ли это, что Gradle думает, что это плохой шаблон?

1 Ответ

0 голосов
/ 28 мая 2018

Я думаю, что вы ищете Дополнительные задачи .Для этого вам нужно определить свой собственный класс задач, но затем вы можете запросить точно измененные файлы в своих входных данных:

@TaskAction
void execute(IncrementalTaskInputs inputs) {
    println inputs.incremental ? 'CHANGED inputs considered out of date'
                               : 'ALL inputs considered out of date'
    if (!inputs.incremental)
        project.delete(outputDir.listFiles())

    inputs.outOfDate { change ->
        println "out of date: ${change.file.name}"
        def targetFile = new File(outputDir, change.file.name)
        targetFile.text = change.file.text.reverse()
    }

    inputs.removed { change ->
        println "removed: ${change.file.name}"
        def targetFile = new File(outputDir, change.file.name)
        targetFile.delete()
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...