Java rule false positive

I think the documentation on Scanner Environment should help you.

Maven / Gradle

If your whole Maven or Gradle build doesn’t run on Java 11 or 17, we suggest first to try to base the whole build on one of those two versions of Java. If it’s not compatible, then you can override the JAVA_HOME environment variable just before the analysis step, as shown here:

# Maven build
mvn verify ...
export JAVA_HOME=/path/to/java-11-or-17
mvn sonar:sonar ...