You should check which Java version is configured in the JAVA_HOME.
Use: mvn -version
You should see something like this from mvn
output
$ mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: path\apache-maven-3.8.5
Java version: 17.0.3.1, vendor: Oracle Corporation, runtime: path\Java\jdk-17.0.3.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
You can also follow this post for more solutions.
https://mkyong.com/maven/maven-error-invalid-target-release-17/