In my case, the pom file is right, the java version, source, target version are set correctly, but I was compiling from command line and the default java interpreter is set to JAVA 1.8. Updating it to JAVA 17 made it work.