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

I’m trying to scan a branch in a GitHub action using: dotnet sonarscanner.

At the end of the workflow (dotnet sonarscanner end) it gets the following error:

Blockquote
Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
15 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

This is the last part of the GitHub action yaml:

    - name: Install SonarCloud
      run: dotnet tool install --global dotnet-sonarscanner

    - name: Begin SonarCloud Scan
      run: |
            dotnet sonarscanner begin /o:"${{ secrets.SONAR_CLOUD_ORGANIZATION }}" \
                                    /k:"${{ env.SONAR_CLOUD_PROJECT_KEY }}" \
                                    /v:"${{ steps.gitversion.outputs.nuGetVersionV2 }}" \
                                    /d:sonar.host.url="${{ secrets.SONAR_CLOUD_URL }}" \
                                    /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
                                    /d:sonar.cs.opencover.reportsPaths=./CoverageResults/coverage.opencover.xml \
                                    /d:sonar.coverage.exclusions="**Test*.cs" \
                                    /d:sonar.qualitygate.wait=true

    - name: Build
      run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} -p:GeneratePackageOnBuild=false

    - name: Test
      run: |
            dotnet test --no-restore --no-build --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} \
                    /p:CollectCoverage=true \
                    /p:CoverletOutput=../CoverageResults/ \
                    /p:MergeWith="../CoverageResults/coverage.json" \
                    /p:CoverletOutputFormat=\"opencover,json\" \
                    -m:1

    - name: End SonarCloud Scan
      run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The solution was to include the following step in the GitHub action

- name: Set up JDK 17
  uses: actions/setup-java@v2
  with:
    java-version: '17' # Set up Java 17, because SonarCloud requires it
    distribution: 'adopt'
1 Like

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