##[error]ERROR: Error during SonarScanner execution

Hello Team,

I am using SonarQube -9.0 Sonar Scanner on an Ubuntu 20.0.4 machine.
I am using Azure DevOps integration for which i have installed Ubuntu (linux agent) on a Ubuntu server (Ex: Server1).

The Azure pipeline runs a javacode which is ANT based project

The Server1, also contains the following

  1. Open-JDK-11 , Java-8
  2. echo $JAVA_HOME = /usr/lib/jvm/java-11-openjdk-amd64/bin
  3. echo $PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-11-openjdk-amd64/bin/bin
    4 Java -version

openjdk version “11.0.14.1” 2022-02-08
OpenJDK Runtime Environment (build 11.0.14.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.14.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

  1. ant -version
    Apache Ant™ version 1.8.4 compiled on May 22 2012

Ran the following pipleline in my Azure DevOps

  - task: SonarQubePrepare@5
    inputs:
      SonarQube: 'sonar_19.0.2'
      scannerMode: 'CLI'
      configMode: 'manual'
      cliProjectKey: 'sandbox'
      cliProjectName: 'project'
      cliSources: '.'
      extraProperties: 'sonar.java.jdkHome=/usr/lib/jvm/java-11-openjdk-amd64/'

  - task: Ant@1
    inputs:
      buildFile: 'pep/jenkins-build.xml'
      options: 
      targets: 'distribution'
      publishJUnitResults: true
      testResultsFiles: '**/TEST-*.xml'
      antHomeDirectory: '/opt/apache-ant-1.9.16'
      javaHomeOption: 'Path'
      jdkUserInputDirectory: '/usr/lib/jvm/java-8-openjdk-amd64/'

  - task: SonarQubeAnalyze@5
  - task: SonarQubePublish@5
    inputs:
      pollingTimeoutSec: '300'

Pipeline failed at the following area:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
022-04-14T02:38:34.1974933Z ##[section]Starting: SonarQubeAnalyze

2022-04-14T02:38:34.1979762Z ==============================================================================

2022-04-14T02:38:34.1979957Z Task : Run Code Analysis

2022-04-14T02:38:34.1980149Z Description : Run scanner and upload the results to the SonarQube server.

2022-04-14T02:38:34.1980309Z Version : 5.4.0

2022-04-14T02:38:34.1980436Z Author : sonarsource

2022-04-14T02:38:34.1980777Z Help : Version: 5.4.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)

2022-04-14T02:38:34.1981165Z ==============================================================================

2022-04-14T02:38:34.3012387Z [command]/home/azureuser/myagent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.4.0/sonar-scanner/bin/sonar-scanner

2022-04-14T02:38:34.3952742Z INFO: Scanner configuration file: /home/azureuser/myagent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.4.0/sonar-scanner/conf/sonar-scanner.properties

2022-04-14T02:38:34.3956501Z INFO: Project root configuration file: NONE

2022-04-14T02:38:34.4056790Z INFO: SonarScanner 4.6.2.2472

2022-04-14T02:38:34.4057548Z INFO: Java 1.8.0_312 Private Build (64-bit)

2022-04-14T02:38:34.4057914Z INFO: Linux 5.13.0-1021-azure amd64

2022-04-14T02:38:34.5604462Z INFO: User cache: /home/azureuser/.sonar/cache

2022-04-14T02:38:34.6125964Z INFO: Scanner configuration file: /home/azureuser/myagent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.4.0/sonar-scanner/conf/sonar-scanner.properties

2022-04-14T02:38:34.6126859Z INFO: Project root configuration file: NONE

2022-04-14T02:38:34.6146554Z INFO: Analyzing on SonarQube server 9.3.0

2022-04-14T02:38:34.6149818Z INFO: Default locale: "en", source code encoding: "UTF-8" (analysis is platform dependent)

2022-04-14T02:38:34.6173551Z INFO: ------------------------------------------------------------------------

2022-04-14T02:38:34.6174904Z INFO: EXECUTION FAILURE

2022-04-14T02:38:34.6175933Z INFO: ------------------------------------------------------------------------

2022-04-14T02:38:34.6176172Z INFO: Total time: 0.230s

2022-04-14T02:38:34.6338875Z INFO: Final Memory: 5M/241M

2022-04-14T02:38:34.6340266Z INFO: ------------------------------------------------------------------------

2022-04-14T02:38:34.6342598Z ##[error]ERROR: Error during SonarScanner execution

2022-04-14T02:38:34.6343626Z ERROR: Error during SonarScanner execution

2022-04-14T02:38:34.6351770Z ##[error]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 Runtime only recognizes class file versions up to 52.0

2022-04-14T02:38:34.6354050Z

2022-04-14T02:38:34.6355606Z ##[error]at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:756)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

2022-04-14T02:38:34.6356858Z at java.lang.ClassLoader.defineClass1(Native Method)

2022-04-14T02:38:34.6357334Z at java.lang.ClassLoader.defineClass(ClassLoader.java:756)

2022-04-14T02:38:34.6357899Z at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

2022-04-14T02:38:34.6358868Z ##[error]at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)

at java.net.URLClassLoader.access$100(URLClassLoader.java:74)

at java.net.URLClassLoader$1.run(URLClassLoader.java:369)

2022-04-14T02:38:34.6359798Z at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)

2022-04-14T02:38:34.6360101Z at java.net.URLClassLoader.access$100(URLClassLoader.java:74)

2022-04-14T02:38:34.6360792Z ##[error]at java.net.URLClassLoader$1.run(URLClassLoader.java:363)

at java.security.AccessController.doPrivileged(Native Method)

2022-04-14T02:38:34.6361238Z

2022-04-14T02:38:34.6361459Z at java.net.URLClassLoader$1.run(URLClassLoader.java:363)

2022-04-14T02:38:34.6361849Z at java.security.AccessController.doPrivileged(Native Method)

2022-04-14T02:38:34.6362834Z ##[error]at java.net.URLClassLoader.findClass(URLClassLoader.java:362)

at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)

at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

2022-04-14T02:38:34.6363600Z at java.net.URLClassLoader.findClass(URLClassLoader.java:362)

2022-04-14T02:38:34.6363947Z at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)

2022-04-14T02:38:34.6365118Z ##[error]at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)

at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2022-04-14T02:38:34.6365781Z

2022-04-14T02:38:34.6366057Z at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)

2022-04-14T02:38:34.6366488Z at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)

2022-04-14T02:38:34.6367411Z ##[error]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

2022-04-14T02:38:34.6367956Z

2022-04-14T02:38:34.6368193Z at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

2022-04-14T02:38:34.6368566Z at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

2022-04-14T02:38:34.6369597Z ##[error]at java.lang.reflect.Method.invoke(Method.java:498)

at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)

2022-04-14T02:38:34.6370263Z at java.lang.reflect.Method.invoke(Method.java:498)

2022-04-14T02:38:34.6370602Z at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)

2022-04-14T02:38:34.6371609Z ##[error]at com.sun.proxy.$Proxy0.execute(Unknown Source)

at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)

at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)

2022-04-14T02:38:34.6372322Z at com.sun.proxy.$Proxy0.execute(Unknown Source)

2022-04-14T02:38:34.6372629Z at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)

2022-04-14T02:38:34.6372991Z at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)

2022-04-14T02:38:34.6373867Z ##[error]at org.sonarsource.scanner.cli.Main.execute(Main.java:112)

at org.sonarsource.scanner.cli.Main.execute(Main.java:75)

at org.sonarsource.scanner.cli.Main.main(Main.java:61)

2022-04-14T02:38:34.6374557Z at org.sonarsource.scanner.cli.Main.execute(Main.java:112)

2022-04-14T02:38:34.6374845Z at org.sonarsource.scanner.cli.Main.execute(Main.java:75)

2022-04-14T02:38:34.6375242Z ##[error]ERROR:

2022-04-14T02:38:34.6375550Z

2022-04-14T02:38:34.6375694Z ERROR:

2022-04-14T02:38:34.6376391Z ##[error]ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

2022-04-14T02:38:34.6377089Z ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

2022-04-14T02:38:34.6522751Z ##[error]The process '/home/azureuser/myagent/_work/_tasks/SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055/5.4.0/sonar-scanner/bin/sonar-scanner' failed with exit code 1

2022-04-14T02:38:34.6539677Z ##[section]Finishing: SonarQubeAnalyze
Finishing: SonarQubeAnalyze

Please suggest if we have been missing anything here. The solution earlier provided in the forum was to set the Java_home path to JDK which is set in this case, yet the problem stays

Hi,

So I guess you already understand that the problem is that analysis is being run with too low a version of Java.

I can see that you’ve tried to fix that, but…

First, I don’t recognize the sonar.java.jdkHome property. Path-to-Java is a value that needs to be set before the scanner is invoked, and any sonar.* property is only going to have impact after the scanner is already running.

This is possibly tangential, but I notice your $PATH ends with /usr/lib/jvm/java-11-openjdk-amd64/bin/bin. You’re trying to put the Java 11 executable in the default path. Unfortunately, that second, trailing bin is going to make the path invalid. So that attempt to make Java 11 the default isn’t working.

First, I notice you’re using Java 8 for your Ant compile. I want to be explicit that I do not think it’s a problem or interfering in any way in analysis.

And, it tells me that Java 8 is (probably) properly installed on your build agent. I would have thought it was set as the default, but your java -version command shows it’s not.

So the question is why your pipeline isn’t using the default Java version. At which point I think this becomes an Azure question, rather than a SonarQube question, and unfortunately I’m quickly out of my depth with Azure. And… this SO answer makes me think that your $JAVA_HOME env var isn’t necessarily the same as Azure’s.

At a minimum, it’s probably worth putting some echo commands in there to learn about the Azure environment.

 
HTH,
Ann