SonarQube 在 Azure Pipelines 上失败,无法加载组件 class org.sonar.scanner.scan.filesystem.InputComponentStore

SonarQube fails on Azure Pipelines with Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore

安装市场插件后,我正在关注 official documentation for my SonarQube installation (8.6 Community)

gradle 插件配置文件:

plugins {
    id("org.springframework.boot") version "2.4.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    id("org.sonarqube") version "3.1.1"
    kotlin("jvm") version "1.4.21"
    kotlin("plugin.spring") version "1.4.21"
}

这是管道的一部分:

        - task: SonarQubePrepare@4
          inputs:
            SonarQube: 'profile-sonarqube'
            scannerMode: 'Other'
            extraProperties: |
              # Additional properties that will be passed to the scanner, 
              # Put one key=value per line, example:
              # sonar.exclusions=**/*.bin
              sonar.projectKey=hello-azure
        - task: Gradle@2
          inputs:
            gradleWrapperFile: 'gradlew'
            tasks: 'build'
            publishJUnitResults: true
            testResultsFiles: '**/TEST-*.xml'
            javaHomeOption: 'JDKVersion'
            sonarQubeRunAnalysis: true
            sqGradlePluginVersionChoice: 'specify'
            sonarQubeGradlePluginVersion: '3.1.1'
        - task: SonarQubePublish@4
          inputs:
            pollingTimeoutSec: '300'

我也试过将 sonar.branch=main 和 sonar.branch.name=main 设置为 extraProperties.

这是完整的日志:

Starting: SonarQubePrepare
==============================================================================
Task         : Prepare Analysis Configuration
Description  : Prepare SonarQube analysis configuration
Version      : 4.17.0
Author       : sonarsource
Help         : Version: 4.17.0. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
Finishing: SonarQubePrepare

...

> Task :compileTestKotlin
> Task :compileTestJava NO-SOURCE

> Task :sonarqube
SonarScanner will require Java 11 to run starting in SonarQube 8.x

> Task :sonarqube FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarqube'.
> No branches currently exist in this project. Please scan the main branch without passing any branch parameters.

这是怎么回事?

更新:

奇怪的是,运行 sonarqube gradle 任务作为管道脚本手动工作正常:

- script: ./gradlew sonarqube -Dsonar.projectKey=hello-azure -Dsonar.host.url=https://mysonarqubeserver  -Dsonar.login=mylogin
        

更新 2:

我把插件版本改成了3.0

        - task: Gradle@2
          inputs:
            gradleWrapperFile: 'gradlew'
            tasks: 'build'
            publishJUnitResults: true
            testResultsFiles: '**/TEST-*.xml'
            javaHomeOption: 'JDKVersion'
            sonarQubeRunAnalysis: true
            sqGradlePluginVersionChoice: 'specify'
            sonarQubeGradlePluginVersion: '3.0'

现在是这样的行为:

日志:

> Task :sonarqube
SonarScanner will require Java 11 to run starting in SonarQube 8.x

> Task :sonarqube FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarqube'.
> Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore

这是完整的堆栈跟踪,根本原因是 Caused by: java.lang.NoSuchFieldError: SHORT:

2021-02-17T22:52:41.8616402Z 2021-02-17T22:52:41.799+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':sonarqube'.
2021-02-17T22:52:41.8617730Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore
2021-02-17T22:52:41.8618768Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2021-02-17T22:52:41.8619739Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
2021-02-17T22:52:41.8620759Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  Run with --scan to get full insights.
2021-02-17T22:52:41.8621690Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2021-02-17T22:52:41.8622648Z 2021-02-17T22:52:41.800+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is:
2021-02-17T22:52:41.9079864Z 2021-02-17T22:52:41.802+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':sonarqube'.
2021-02-17T22:52:41.9081980Z 2021-02-17T22:52:41.803+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid(ExecuteActionsTaskExecuter.java:200)
2021-02-17T22:52:41.9083995Z 2021-02-17T22:52:41.803+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
...
2021-02-17T22:52:41.9577148Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: java.lang.IllegalStateException: Unable to load component interface org.sonar.scanner.scan.branch.BranchConfiguration
2021-02-17T22:52:41.9578725Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:66)
2021-02-17T22:52:41.9580213Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
2021-02-17T22:52:41.9581700Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.parameters.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:118)
2021-02-17T22:52:41.9583224Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.parameters.ComponentParameter.resolveInstance(ComponentParameter.java:136)
2021-02-17T22:52:41.9584690Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
2021-02-17T22:52:41.9586243Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
2021-02-17T22:52:41.9587728Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.ConstructorInjector.run(ConstructorInjector.java:335)
2021-02-17T22:52:41.9589239Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
2021-02-17T22:52:41.9637580Z 2021-02-17T22:52:41.849+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
2021-02-17T22:52:41.9639629Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
2021-02-17T22:52:41.9641227Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
2021-02-17T22:52:41.9642650Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
2021-02-17T22:52:41.9644254Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
2021-02-17T22:52:41.9645676Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
2021-02-17T22:52:41.9647288Z 2021-02-17T22:52:41.850+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:64)
2021-02-17T22:52:41.9648493Z 2021-02-17T22:52:41.851+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  ... 129 more
2021-02-17T22:52:41.9649561Z 2021-02-17T22:52:41.851+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: java.lang.NoSuchFieldError: SHORT
...
2021-02-17T22:52:41.9729914Z 2021-02-17T22:52:41.851+0000 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 1m 42s

SonarQube fails on Azure Pipelines with Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore

这个问题似乎是 SonarQube 版本与 Plugin Version Community Branch Plugin 不兼容。

您可以尝试使用 SonarQube 版本:8.1 和插件版本:Community Branch Plugin 1.3.0 (communityBranchPlugin)。

注意: 8.2 及以上版本需要单独发布,因为这些版本有进一步的变化。

请查看 Github 上的话题 SonarQube 8.1 Support 了解更多详情。