Clean after "Switch To"

(Not sure if this is a Buildship question or an EGit one)
Every time I switch to a different git branch using the “Team > Switch To” menu, the “build” folder still holds the classes from the other branch and I’m forced to do a manual “clean” otherwise the build task won’t find any changes. Can the cleaning be automated somehow?

Are you referring to Eclipse’s Clean and Build commands or to Gradle’s build task?

The gradle clean/build.

I don’t understand what you mean by “doesn’t find any changes”. Gradle will notice changes to task inputs. Can you elaborate?

I think this is what happens:

  • I am on the master branch, and everything builds fine
  • I switch to branch “fix1”, make changes to the sources, build, etc. and it works fine
  • I switch back to master. The build folder is the same as it was when I was working on “fix1”, with class files compiled from the “fix1” sources. When I build, gradle thinks that all is up to date because (I guess) the sources on master are older than the .class files coming from the “fix1” build

This is my interpretation of what happened when gradle refused to rebuild the classes when generating the project jar.

Gradle uses equality on the timestamps and lengths of files. It does not ignore “older” files. So if there is a difference between “master” and “fix1”, it will recompile. If this does not happen, can you please create a reproducible example on GitHub?