Task is always UP-TO-DATE when inputs and outputs are changed


(Kushal Kadaba) #1

I have written a Task to generate some POJO files inside a package. In the constructor of this Task I’ve the following code

File inpFile = new File('buildSrc/src/main/groovy/example/plugins/greenDAO/Generator.java')
project.afterEvaluate {
            String path = getProject().extensions.greenDAO.path + "/" + packageName.replaceAll('\\.',"/")
            File outputDir = new File (path);
            inputs.file inpFile
            outputs.dir outputDir
        }

However, the task is always considered UP-TO-DATE even when I make changes to my Generator.java or delete some files in the ouputDir. The way I read it in the documentation was that gradle maintains a hash and if the hash changes because of the changes in the inputs/outputs it will rerun the task. What am I doing wrong here?


(René Groeschke) #2

Have you tried running your build with the -i flag? this info log level should give you a hint why gradle considers the task to be up-to-date.


(Kushal Kadaba) #3

I did, but I don’t see a difference.

In-memory cache of /Users/kushalkadaba/Desktop/MyApp/buildSrc/.gradle/2.10/taskArtifacts/fileHashes.bin: Size{162}, CacheStats{hitCount=6083, missCount=656, loadSuccessCount=0, loadExceptionCount=0, totalLoadTime=0, evictionCount=0}
In-memory cache of /Users/kushalkadaba/Desktop/MyApp/buildSrc/.gradle/2.10/taskArtifacts/outputFileStates.bin: Size{2}, CacheStats{hitCount=125, missCount=6, loadSuccessCount=0, loadExceptionCount=0, totalLoadTime=0, evictionCount=0}
In-memory cache of /Users/kushalkadaba/Desktop/MyApp/buildSrc/.gradle/2.10/taskArtifacts/fileSnapshots.bin: Size{42}, CacheStats{hitCount=0, missCount=9, loadSuccessCount=0, loadExceptionCount=0, totalLoadTime=0, evictionCount=0}
In-memory cache of /Users/kushalkadaba/Desktop/MyApp/buildSrc/.gradle/2.10/taskArtifacts/taskArtifacts.bin: Size{2}, CacheStats{hitCount=69, missCount=9, loadSuccessCount=0, loadExceptionCount=0, totalLoadTime=0, evictionCount=0}

Strangely enough, the :compileGroovy task recognized the difference
> Executing task ‘:compileGroovy’ (up-to-date check took 0.012 secs) due to:

  Input file /Users/kushalkadaba/Desktop/MyApp/buildSrc/src/main/groovy/example/gradle/plugins/greenDAO/Generator.java has changed.

(Kushal Kadaba) #4

I figured out what I was doing wrong. The piece of code was placed in the build.gradle of the app folder in the android project. buildSrc was a subfolder of the root project. So inpFile was never found. A file.exists check revealed this blunder. According to the documentation:

A task with only outputs defined will be considered up-to-date if those outputs are unchanged since the previous build.

This was why changes to the input file was never registered.
Although, I still have a question. According to the documentation:

Note that if a task has an output directory specified, any files added to that directory since the last time it was executed are ignored and will NOT cause the task to be out of date

I deleted a file from the output directory. This should have made the task out-of-date but it didn’t. Is this expected behavior? Am I reading the documentation wrong?

PS: I did check if the output directory exists and it does.