To solve this issue, simply wrap the sourceCompatibility with java as follow and update all deprecated plugins to latest versions:
java { sourceCompatibility = '21' }