We run build without clean on our build servers, and the build can run on any of four build agents. I have a problem where the class file of a deleted java file still lingers in the build/classes folder – it won’t be deleted until we perform a clean build.
(And since we have four randomly chosen build agents, I must make sure that we clean on all of them.)
Is there a way to make sure class files of deleted java files doesn’t linger in the build/classes folder?
‘JavaCompile’ tasks automatically clean all class files generated on the previous run before kicking off compilation. This is done exactly to prevent stale class files. Not sure why this doesn’t seem to be working in your case.
This is a test class in the buildSrc folder, maybe that’s treated differently?
Was it the only test in buildSrc by any chance? ie is buildSrc/src/test/java now empty/removed?
That is a known problem with the current implementation unfortunately. The JavaCompile task cleans previously generated class files, but it will not run if there are no source files to compile. So, when you delete the last source file in a sourceset, you will run into this problem.
OK, bummer. But another thing: why doesn’t even the “clean” task take care for this?
huh? I thought you said running clean did get rid of the stale class file?
Oops, that’s wrong, sorry. I actually do a “git clean -dqfx”, since “./gradlew clean” doesn’t remove that file.
ok right - the reason is that ‘gradle clean’ does not clean the buildSrc project (since it would be unusual to want that) and also the buildSrc project is built first no matter what you run, including clean.