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 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.