Error with DotNet and Java version

Hi we have our pipeline with this commands

we are using this commands
dotnet tool update --global dotnet-sonarscanner --version 6.0.0
dotnet sonarscanner begin
dotnet sonarscanner end

and we are getting this error

Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61), this version of the Java Runtime only recognizes class file versions up to 55.0
The SonarScanner did not complete successfully

we have java version 1.8

PS C:\Users\lprada> java --version
openjdk 18.0.2.1 2022-08-18
OpenJDK Runtime Environment Temurin-18.0.2.1+1 (build 18.0.2.1+1)
OpenJDK 64-Bit Server VM Temurin-18.0.2.1+1 (build 18.0.2.1+1, mixed mode, sharing)

what we can do is blocking our development

Hey there.

Can you share your Bitbucket Pipelines YML?

  • dotnet tool update --global dotnet-sonarscanner --version 6.0.0
  • dotnet sonarscanner begin /k:“XXXXXXXXX” /d:“sonar.token=YYYYYYY” /o:“ZZZZZZZZZ” /d:“sonar.host.url=https://sonarcloud.io” /v:1.10
  • invoke-expression -Command “msbuild.exe api.csproj /t:rebuild /p:PlatformTarget=anycpu /p:Configuration=DEBUG /p:OutputPath=C:\temp”
  • dotnet sonarscanner end /d:“sonar.token=YYYYYYYYY”

Hey there.

Not just a snippet – your full file, please.

All of it? We have private data there. What info do you need, is a runner in a windows server.

The Docker image used in a good start – but really your full pipeline configuration is going to be the most useful.

I will try to delete all private info. But as I said this is running in a windows runner in our own vm with windows server. The pipeline is using the las version of atlassian but this especific part of the execution is running locally

Source: SonarScanner for .NET (sonarsource.com) :

  • Java 17 is required to run this version of the scanner. If you are running a previous version of Java, you will need a previous version of the scanner.

Addendum: expected this requirement to cause problems on GitHub.
The default java version on their ubuntu-latest runner image is Java 11.

This is the full pipeline. The step is running in a windows self hosted. We hace install there java 1.18

This is an example Starter pipeline configuration

Use a skeleton to build, test and deploy using manual and parallel steps

-----

You can specify a custom docker image from Docker Hub as your build environment.

image: atlassian/default-image:latest

clone:
depth: full
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &deploy-azure-vm
name: Deploy To Windows
deployment: DEV
runs-on:
- ‘windows’
- self.hosted
script:
- dotnet new tool-manifest
- dotnet tool update --global dotnet-sonarscanner --version 6.0.0
- dotnet sonarscanner begin /k:“cardinalproductteam_notif_api” /d:“sonar.token=$Env:SONAR_TOKEN” /o:“cardinal-ecm-team” /d:“sonar.host.url=https://sonarcloud.io” /v:$SEMANTIC_VERSION
- invoke-expression -Command “build/buildtools/MSBuild/Current/Bin/msbuild.exe ./Fuentes/Cardinal.Notifications/Cardinal.Notifications.API/Cardinal.Notifications.API.csproj /t:rebuild /p:PlatformTarget=anycpu /p:Configuration=$BUILD_CONFIG /p:OutputPath=$Env:BUILD_DIRECTORY”
- Write-Host “Eliminar Archivos de Env.Config”
- dotnet sonarscanner end /d:“sonar.token=$Env:SONAR_TOKEN”
- Write-Host “Deploy Finalizado.”;

options:
max-time: 20

pipelines:
branches:
develop:
- step:
<<: *deploy-azure-vm
name: Deployment to Infra Windows
deployment: infra-windows
runs-on:
- ‘windows’
- self.hosted
- ‘infra’

We have java 18 install, I believe it should work.

I have added the pipeline, please nay help will be great because we have to disabled the sonar check to continue deploying.

Looks like you are running the pipeline using atlassian/default-image:latest.
Installing a runtime on the agent host has no influence if the pipeline is running in a container.
You should check the java version installed in the docker image itself.

Also note that Java 18 is unsupported since september 2022.

The container is not use in the step with the error. The step is running in the local vm with a runner with java 18 install

More than 8 days without a response. I need help form the sonar support how can I get it?

More than 8 days without a response. I need help form the sonar support how can I get it? this is preventing us for using sonnar

This is a Community Forum, as noted in the FAQ

  • If you need SLAs, guaranteed response, privacy, SonarSource also offers Commercial Support.

I would suggest checking what version of java your JAVA_HOME variable is pointing to, and adjusting if it’s a distro other than Java 17+ (and @ArwynFr is right, you should avoid Java 18, since it’s EOL).

After a lot of reinstallment of java I get know this error

SonarScanner for MSBuild 6.1

3

Using the .NET Core version of the Scanner for MSBuild

4

Post-processing started.

5

14:02:37.563 14:02:37.563 WARNING: File 'C:\windows\temp\9d9e9ea6-23e7-5bb8-baa0-421a1e7d2b86\1707317664349\build\Fuentes\Cardinal.CPP\Cardinal.CPP.DTO\stylecop.json' does not exist.

6

Calling the SonarScanner CLI...

7

Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main

8

java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

9

The SonarScanner did not complete successfully

10

14:02:37.756 Post-processing failed. Exit code: 1

11

also we migrate to java 21