在任务的配置阶段,我将一些目录注册为builtBy: thisTask
。我希望gradle能够自动检测源是否已更改,但是任务总是在执行。
这是任务:
subprojects {
def srcMainMirah = file('src/main/mirah')
if (srcMainMirah.exists()) {
idea.module.sourceDirs += srcMainMirah
task compileMirah {
def classesMirahMain = file("$buildDir/classes-mirah/main")
inputs.sourceDir srcMainMirah
def thisTask = delegate
sourceSets.main {
output.dir(classesMirahMain, builtBy: thisTask)
java.srcDir srcMainMirah
}
dependsOn tasks.compileJava
doFirst {
def classpath = files("$buildDir/classes/main").plus(configurations.compile)
mirahc(srcMainMirah, classesMirahMain, classpath)
}
}
}
}
它用于以mirah语言编译源代码,就像Java编译器一样,它会生成
*.class
文件。
最佳答案
仅声明任务的输入不足以确定任务是否最新。您还必须声明task.outputs
A task with no defined outputs will never be considered up-to-date. For scenarios where the outputs of a task are not files, or for more complex scenarios, the
TaskOutputs.upToDateWhen()
method allows you to calculate programmatically if the tasks outputs should be considered up to date.A task with only outputs defined will be considered up-to-date if those outputs are unchanged since the previous build.
从section 17.9.1 here。
关于groovy - Gradle任务永远不会是最新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34785969/