How to use a different runtime JDK from what SonarQube uses

Hi,

I wanted to use SonarQube on a local maven project that uses Java 1.8. I found this document while researching for a solution but I am not sure where we are setting the value for sonar.java.jdkHome. Please share the details. Thanks

  • I am using sonarqube-9.3.0.51899 on Mac macOS Big Sur
  • I am trying to generate a Sonar report for a project that uses Java 1.8 while the installed SonarQube works with Java 11
  • At first, I changed the Java version to 11 and run the project but the builds were failing then found out that it uses the 1.8 version. Therefore, I have been researching for a solution.

Thank you!

It really all depends on how your build process works. What it comes down to is simple. You have to compile your code and run tests on it with Java 8, but run the sonar-scanner or “sonar:sonar” goal with Java 11.

For instance, in our enterprise, where we run builds with Jenkins, we constructed Docker images that either contain Java 8 or Java 11, and in the Jenkins pipeline script where we run “mvn sonar:sonar”, we wrap it in a “docker.image.inside” pipeline step that uses the Java 11 image. The compile and test stages use the image that has Java 8.

1 Like

I just use mvn clean install for building the project, which is now failing. So, I wanted to change the runtime JDK back to 1.8 and set the sonar.java.jdkHome to 11. In which file do I set that? Is it in the sonar.properties file?

Thanks

First of all, I suggest you remove the sonar plugin from the pom, so it doesn’t run as part of the normal build.

Then, run the build process in multiple steps. The first phase, with the Java 8 compiler, would just be “mvn clean package”. When that’s complete, switch to the Java 11 compiler and run “mvn sonar:sonar”.

2 Likes