'Sonarqube scan with different java version than project

I have a project which is written in java 8. It is kind of complex for me and very dependent to java 8. However I also happen to have a SonarQube and a Jenkins instance which is trying to use java 11 to scan the projects.

When java 11 is used to run:

mvn clean verify

I get java 8 dependency errors in the project and when I use java 8 I can not use sonarscanner.

I could not find and answer yet.

Any solution or suggestions ?



Solution 1:[1]

You can use your Jenkins instance (using JDK8) to build and submit the project to your SonarQube instance running on JDK11.

Using SonarQube's recommended scanner you can configure your project to use the remote SQ server:

pom.xml

<properties>
        <sonar.host.url>https://sonarqube.cldbz.net/</sonar.host.url>
        <sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
        <sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.sources>src/main</sonar.sources>
</properties>

and then trigger the scanning process on Jenkins with mvn sonar:sonar which would submit your project's scan results to your SQ server.

You can even test this without pom.xml changes:

mvn clean verify sonar:sonar -Dsonar.login=<token> -Dsonar.host.url=https://<sonar-server>:<port>.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tasos P.