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

Posted

技术标签:

【中文标题】SonarQube 在 Azure Pipelines 上失败,无法加载组件类 org.sonar.scanner.scan.filesystem.InputComponentStore【英文标题】:SonarQube fails on Azure Pipelines with Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore 【发布时间】:2021-05-20 15:27:45 【问题描述】:

安装市场插件后,我关注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'

现在这是行为:

如果之前未在 SonarQube 上创建应用程序,则第一次可以正常工作。 后续构建失败并显示Unable to load component class org.sonar.scanner.scan.filesystem.InputComponentStore

日志:

> 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$1(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$1.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$1.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$1.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

【问题讨论】:

【参考方案1】:

SonarQube 在 Azure Pipelines 上失败,无法加载组件类 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 了解更多详情。

【讨论】:

以上是关于SonarQube 在 Azure Pipelines 上失败,无法加载组件类 org.sonar.scanner.scan.filesystem.InputComponentStore的主要内容,如果未能解决你的问题,请参考以下文章

为啥 SonarQube 不从 yaml 构建更新 Azure DevOps 质量门状态?

SonarQube Azure Devops 未授权

Azure DevOps 中项目的 Sonarqube 扫描问题

与 Azure DevOps 集成时出现 sonarqube 错误

Sonarqube ANT 为 SAP Hybris 构建 azure devops

如何将 sonarqube 集成到 azure CI