Gradle compileJava task run even during clean?
Question
When you are using the java plugin with gradle, and do only a clean of a project, is the compileJava task still run?
Solution
By default, the clean
task doesn't depend on any other task, so the answer is no. If you observe this, it means that a build script or third-party plugin has added a task dependency from clean
to compileJava
(or to some other task that in turn depends on compileJava
).
OTHER TIPS
When trying to understand this or even figuring it out yourself via some exploratory coding(i.e. adding println statements or the like) - make sure you're aware of the multi-phase execution model of Gradle: http://gradle.org/current/docs/userguide/build_lifecycle.html
In a scenario where your clean target won't actually execute, it will still be configured - so if you've added your cleanup code to the wrong place, it will get executed every time, here's an example: http://gradle.org/current/docs/userguide/potential_traps.html#configuration_and_execution_phase