sonar-scala / sbt-sonar

An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.
https://sonar-scala.com/docs/setup/sbt-sonar
Apache License 2.0
62 stars 18 forks source link

Plugins ignore some properties #209

Closed JFCote closed 3 years ago

JFCote commented 3 years ago

When upgrading to SonarQube server version: 9.1.0 with a Java 1.8 project, I receive this error when trying to scan my project:

[error] (sonarScan) java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runti
me only recognizes class file versions up to 52.0

I've read the documentation, and this is because the default sonar-scanner is now using JDK 11. There is a very simple way to get around this explained here: https://docs.sonarqube.org/latest/analysis/languages/java/#header-2

This is the important part:

In some situations, you might have to analyze a project built with a different version of Java than the one executing the analysis. The most common case is to run the analysis with Java 11, while the project itself uses Java 8 or before for its build. This case is normally automatically handled when using Maven or Gradle, as well as with any flavor of SonarLint. If it is your case, and you are NOT using Maven or Gradle, you will need to set the property sonar.java.jdkHome manually (see below).

I tried to provide this variable both in the build.sbt and in the command line. It is totally ignored by the plugin and the build always show the same error.

Here is an example of the command line used:

sbt -Dsonar.host.url=https://my-sonarqube.com -Dsonar.login=whatever -Dsonar.java.jdkHome=/usr/lib/jvm/java-1.8.265 sonarScan

Is this a bug? Is there any other way to analyse using java 8 instead of java 11?

Thanks

JFCote commented 3 years ago

I have find a workaround by changing the JAVA_HOME between the build step and the scan step. No need for these properties.