I’m using SonarCloud on a few of my GitHub repos. Today I realized that there are some errors in the GitHub Actions build log:
[ERROR] Unable to parse source file : 'src/main/java/com/github/beatngu13/knapsackproblem/so/SingleObjectiveProblem.java'
[ERROR] Parse error at line 19 column 51: References to interface static methods are allowed only at source level 1.8 or above
[ERROR] Unable to parse source file : 'src/main/java/com/github/beatngu13/knapsackproblem/base/KnapsackFactory.java'
[ERROR] Parse error at line 49 column 12: Lambda expressions are allowed only at source level 1.8 or above
[ERROR] Unable to parse source file : 'src/main/java/com/github/beatngu13/knapsackproblem/mo/ga/KnapsackChromosome.java'
[ERROR] Parse error at line 36 column 9: Method references are allowed only at source level 1.8 or above
...
The project itself uses Maven, where I set the Java version via the compiler plugin (see pom.xml). Sonar is triggered via Maven sonar:sonar as well (see build config).
Is there a configuration I’m missing that tells Sonar to use the Java version declared in the pom.xml, or how can I fix this?
The scanner for Maven reads the source and the target versions as declared by the maven compiler plugin. The --release is new to Java 9 and I don’t think the scanner supports it.
I’d try setting the properties maven.compiler.source and maven.compiler.target. If you want to set it at the scanner directly, you can use sonar.java.source and sonar.java.target.
Should this be reported as a bug? Java 11 is officially supported, so I assume users expect Sonar to automatically obtain the Java version from the pom.xml?