It seems like the issue was caused by changing the base and build images when upgrading to Java 21. After changing it to maven:3.9.6-eclipse-temurin-21 solved my problem.
maven:3.9.6-eclipse-temurin-21