Are you building on Windows? If so, is your project in a folder synced with OneDrive? Thats the error that randomly occurs when the project is in a OneDrive folder. Its
https://github.com/gradle/gradle/issues/22002 which really should be reopened.
Its random when it decides to error, so upgrading gradle to 8.4 is likely a placebo if it is this issue you're running into, and it will fail again. Luckily the solution is easy, just move the project to a folder that isn't in OneDrive.