The strangest Gradle or Spring problem of my career so far...

Since Friday afternoon last week (17th June 2022) I’ve been struggling with a strange build problem. Usually I’m doing fairly ok with build stuff.

Having run out of ideas and having spent a full day on this problem, I eventually wiped my harddisk, reinstalled MacOS and everything worked again. It wasn’t worth further effort, but the curiosity about what happened remains. That’s why I wrote this blog post.

Disclaimer: I’m quite used to Maven, but Gradle doesn’t constantly give me grief. It’s been quite reliable since I’ve started using it daily about 9 months ago. I find the build lifecycle of Maven a bit clearer and also the clarity it gives beginners. Gradle on the other hand seems to offer more enterprise features regarding insight into your builds, caching and parallel builds. I appreciate that too. This post isn’t about Maven vs. Gradle. Use what suits your needs, be catmatic, not dogmatic.

At work we’re using Gradle (gradlew) with Gradle Enterprise and my build seemed to report test results from a build state that did not reflect the code in the branch anymore. Specifically, tests were failing with Spring reporting a missing bean, but the current version on my branch clearly had the fix in it.

Whenever Gradle was running any Spring test, the test failed with an exception saying a Spring Bean was missing. That was the case before, but we had fixed it around Friday afternoon already. From then on, the tests broke on the original branch we were working on, but also on branches we hadn’t even merged into, including mainline.

What added to the strangeness was that the build ran without issues on multiple coworkers’ machines. The build also ran without problems in CI (Gitlab).

Here are the things I’ve tried to solve the problem until about Tuesday at lunchtime while simultanteuously doing regular work and pairing on my colleague’s machines.

I had:

  • removed ~/.gradle
  • removed $REPO/.gradle
  • used a different JDK (17-open in sdkman instead of 17.0.2.8.1-amzn)
  • removed the repo and cloned it again
    • to the same folder name
    • to a different folder name
  • removed all IntelliJ files from the repo (.idea, .iml)
  • removed all build folders manually
  • ran the build with a different OS (MacOS, latest Monterey) user
  • ./gradlew clean test --no-daemon --no-build-cache
  • ./gradlew clean test --offline --no-daemon --no-build-cache
  • git clean -fdX
  • built with Gradle 7.4.1 instead of 7.4.2
  • compared builds in Gradle Enterprise: no significant differences
  • running the build with WiFi disconnected:
    • didn’t run into that specific problem
    • the build broke earlier because database connections were required
    • not sure if that would have been a road to pursue
  • ran First Aid on my disks from MacOS recovery

My current theory is caching, either on the Gradle side for test results in Gradle Enterprise, or on the Spring side because of caching the test application context.

If anybody reads this and has an idea, solution or explanation. Please contact me or on Twitter.