Best practice for CI: to clean or not to clean?

Because Gradle is so smart about what changed in a project between builds, and therefore what it can skip because it’s already correct (class files, XSD code gen etc), it’s tempting to not do a “clean” for CI builds, as this will significantly speed up the build. On the other hand, you run an increased risk of certain stale artifacts being included in the build due to unforseen reasons or change vectors Gradle doesn’t consider.

So, what’s the best practice here? Should I always do a “gradle clean” before every CI build?

Thanks in advance, Maarten

I would start out without clean for more frequent CI builds (e.g. commit builds), and with clean for less frequent builds (e.g. nightly builds) or builds in later pipeline stages (continuous delivery). If this proves to be reliable enough (and I’d expect it to), it’s a decent compromise between performance and safety.

I would personally clean using gradle’s clean task, then execute anything else. I do not recommend using your CI’s settings (Jenkins and Atlassian Bamboo have this) that tell it to ‘wipeout’ or ‘clean’ each build, because this often means the VCS will be wiped out and cloned or checked-out instead of updated, which if you are like me and want fast CI builds, its not a good idea (especially with a large repository).