1

In the configuration phase of the task I register some dir as builtBy: thisTask. I expect gradle to automatically detect if sources were changed, but the task always being executed.
Here is the task:

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)
            }
        }
    }
}

It is for compiling sources in mirah language, which produces *.class files just like java compiler does.

guai
  • 780
  • 1
  • 12
  • 29

1 Answers1

6

Declaring inputs alone for a task is insufficient to determine if the task is up-to-date. You are required to also declared 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.

From section 17.9.1 here.

Community
  • 1
  • 1
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • `output.dir(classesMirahMain, builtBy: thisTask)` should register `classesMirahMain` dir as output of `thisTask` isn't it? – guai Jan 19 '16 at 10:16
  • 1
    output dir is recognized automatically as outputs only for tasks of type `Copy` – RaGe Jan 22 '16 at 18:51