groovy - Gradle任务永远不会是最新的

标签 groovy gradle build mirah

在任务的配置阶段,我将一些目录注册为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/

相关文章:

grails - 独立 GORM 脚本当前的依赖项是什么?

groovy - Groovy 中 NullObject 类的用途是什么?

android - 在Android Studio上使用lib db4o

asp.net-mvc - Visual Studio : How to override the default "Build Action" for certain extension types per project or solution?

android - 构建 Android 项目时无法识别新版本代码

spring - 混合 Java/Groovy 源的 Gradle 编译排序问题

swing - valueChanged gui 列表执行两次

go - 如何使用 Golang 包以外的名称构建可执行文件

android - 无法解决Android Studio 3.0.1中的所有依赖关系

android - 如何在 androidTest 配置中排除或替换应用依赖项