Severe up-to-date check bug in case of deleted files

Problem

Gradle up-to-date check does not take into account deleted files. This has been confirmed for Gradle 1.3 with ‘java’ and ‘groovy’ plugins.

Steps to reproduce:

  1. Create a build.gradle containing
apply plugin: 'java'
  1. Create the directories src/main/java 3. Create a file src/main/java/Foo.java containing
public class Foo {}
  1. Execute
gradle build
  • compileJava will be executed. 5. Execute
gradle build
  • compileJava will be UP-TO-DATE. 6. Delete the file src/main/java/Foo.java. 7. Execute
gradle build
  • compileJava will still be UP-TO-DATE.

Result Because of this, the deleted class will still be available in both build/classes/main and the created jar in build/lib.

In your scenario, you delete all source files. The problem is that gradle marks the compile task as up-to-date as soon as sources is empty. If this is a problem in your build this workaround might help:

if(sourceSets.main.allJava.empty){
 compileJava.dependsOn cleanCompileJava
 }

But isn’t this a quite evil bug nevertheless?

If compileJava was previously involved in the creation of classes and/or jar then those tasks need to be considered changed if compileJava won’t be executed anymore.

We had the situation that we renamed the whole src/main/java folder to src/main/groovy. We also did some refactoring that resulted in the deletion of some classes. But all previously compiled classes were still kept in both the classes and lib resulting in utter chaos. The local build was still working (until performing a mavenesque manual ‘clean’) but our CI server that always performs a clean build was puking because one of the deleted classes was still used in a test…

I think that an empty directory shouldn’t be considered UP-TO-DATE but something else, like e.g. SKIPPED, thus resulting in a refresh of dependent tasks.

Hey Huxi,

It’s defnitely a bug you’re running into. The workaround is just … well a workaround ;-). We’ll export this thread here to our jira.

Thanks, that’s all I wanted to hear. :wink:

Thank you for the report. I’m glad, that we could make you happy that easily just before the weekend starts :wink:

best regards, René