App fails when .gradle is not deleted after switching branch

We are using gradle 3.2.1 in a Spring Boot project with a mix of Java, Groovy, and TypeScript.
We have a problem when switching branches that currently we can only resolve by deleting the top-level “.gradle” folder after switching the branch:

  • On master everything works fine.
  • Switch to an older release branch
  • gradle clean
  • grade build seems to works fine, but
  • gradle bootRun
    => app fails with strange Oracle connection problem halfway through running DB migrations
    (java.sql.SQLException: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired)

When I delete the “.gradle” folder and just restart “gradle bootRun” it works fine.

(Actually just deleting taskArtifacts.bin and taskArtifacts.lock seems to suffice.)

What can I do to fix this or further research it?

I learned that I cannot delete the “.gradle” folder from a running gradle task, so deleting it from within the “clean” task probably does not work, right?