Having set the JAVA_HOME in om-premise agent to point to jdk 17 but still getting error

Hi

I have a build agent for azure devops, on windows 2023 with following jdk version :

image

But the “Run Code Analysis” fails :

2023-12-12T10:22:36.8164082Z ##[error]Exception in thread “main” java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main 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

it happens when “sonar-scanner.bat” called:

5.18.4\classic-sonar-scanner-msbuild\sonar-scanner-4.8.1.3023\bin\sonar-scanner.bat

But when I manually run the command inside the agent, it publish the results to the SonarQube server.

SonarScanner.MSBuild.exe begin /k:“project-key” /d:sonar.token=“myAuthenticationToken”
MSBuild.exe <path to project file or .sln file> /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.token=“myAuthenticationToken”

Or when I run the “sonar-scanner.bat” manually in the agent command prompt it also succussed:

image

sonar-scanner version: 4.8.1.3023

Despite that “java -version” shows me that I am using version 17.0 of jdk, I am still getting the error:

image

Error :

##[error]Exception in thread “main” java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main 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 versio
##[error]ns up to 52.0

I have enabled the sonar.verbose=true, but can not see which java version the sonar scanner is using.

This is duplicate, cause I have already asked Having set the JAVA_HOME in om-premise agent to point to jdk 17 but still getting error but @ganncamp splited my reply to this thread from his post :
Understanding `java.lang.UnsupportedClassVersionError`

It seems that I had to restart agent service inside the build agent machine, in order for it to detect the java_home !

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.