Unable to push Sonar Reports to SonarQube for Java 8 Maven Project

Hi Team,

I would like to get some help to resolve my issue.

Currently, I have JAVA 8 Maven project which is pretty old one and there is no scope to upgrade to JAVA 11. And the pipeline I am using is Jenkins.

Here, I can successfully able to build and test JAVA 8 project and when I tried to do a Sonar Scan to push the results/reports to SonarQube it failed with incompatible version, which is asking to set JAVA_HOME to Java 11.

So, i have tried to maintain two docker images one with Java 8 and one with Java 11. In Java 8 container I have done all the build and test, and In Java 11 container I run the sonar scan. Please find below.

container('java 8') {
      stage('Build') {
          echo 'echo "in Build"'
          sh '''
              java -version     // Java version: 1.8.0_212, vendor: IcedTea, runtime: /usr/lib/jvm/java-1.8-openjdk/jre
              echo $JAVA_HOME     // /usr/lib/jvm/java-1.8-openjdk
              mvn clean install

container('java 11 - sonar') {
      stage('Sonar Analysis') {
          echo 'echo "in Sonar Analysis"'
          sh '''
              java -version   // Java version: 11.0.10, vendor: AdoptOpenJDK, runtime: /opt/java/openjdk
              echo $JAVA_HOME  //          /opt/java/openjdk
              mvn sonar:sonar

Now, I am receiving a different error saying that Could not find artifact jdk.tools:jdk.tools:jar:1.7 at specified path /opt/java/openjdk/…/lib/tools.jar.

Could you please help us how to come over this error without moving the code to java 11.

Hey there.

Ideally, the scan should be taking place in the same build environment as your build and having access to the build artifcacts, even if you are using a different version of Java to perform the scan. This would imply, in your setup, a container with both versions of Java installed (and switching between them before running mvn sonar:sonar