This build problem happens if you have updated java dependencies but did not upgrade Maven version. Make sure you have running the same/newer version locally on build agent and eg. GitHub actions.
Use mvn --version to verify Maven you are using.
mvn --version