如何解决声纳错误:无法加载组件类 org.sonar.scanner.scan.ProjectLock
Posted
技术标签:
【中文标题】如何解决声纳错误:无法加载组件类 org.sonar.scanner.scan.ProjectLock【英文标题】:How to solve Sonar error: Unable to load component class org.sonar.scanner.scan.ProjectLock 【发布时间】:2017-11-23 23:14:48 【问题描述】:在我的 netbeans 项目上运行 Sonar 时遇到了一些问题。它不工作,我有以下错误:
C:\Users\remy.fischer\Desktop\NetBeansProjects\NetBeansProjects\BinPacking\sonar-scanner-3.0.3.778-windows\bin>sonar-scanner -Dsonar.projectKey=..... -Dsonar.projectName=...
INFO: Scanner configuration file: C:\Users\remy.fischer\Desktop\NetBeansProjects
\NetBeansProjects\BinPacking\sonar-scanner-3.0.3.778-windows\bin\..\conf\sonar-s
canner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows 7 6.1 amd64
INFO: User cache: C:\Users\remy.fischer\.sonar\cache
can't open C:\Users\remy.fischer\Desktop\NetBeansProjects\NetBeansProjects\BinPa
cking\sonar-scanner-3.0.3.778-windows\jre\lib\tzmappings.
INFO: Load global settings
INFO: Load global settings (done) | time=62ms
INFO: User cache: C:\Users\remy.fischer\.sonar\cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=0ms
INFO: SonarQube server 6.4.0
INFO: Default locale: "fr_FR", source code encoding: "UTF-8"
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1.248s
INFO: Final Memory: 39M/178M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:283)
at org.sonar.scanner.scan.ProjectScanContainer.doBeforeStart(ProjectScanContainer.java:110)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:144)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:129)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:118)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:117)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
at org.picocontainer.parameters.BasicComponentParameter$1.resolveInstance(BasicComponentParameter.java:118)
at org.picocontainer.parameters.ComponentParameter$1.resolveInstance(ComponentParameter.java:136)
at org.picocontainer.injectors.SingleMemberInjector.getParameter(SingleMemberInjector.java:78)
at org.picocontainer.injectors.ConstructorInjector$CtorAndAdapters.getParameterArguments(ConstructorInjector.java:309)
at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:335)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:69)
... 23 more
emy.fischerDesktopNetBeansProjectsNetBeansProjectsBinPackingsrcbinpacking
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.nio.file.Paths.get(Paths.java:84)
at org.sonar.scanner.scan.ProjectReactorBuilder.resolvePath(ProjectReactorBuilder.java:395)
at org.sonar.scanner.scan.ProjectReactorBuilder.checkExistenceOfPaths(ProjectReactorBuilder.java:385)
at org.sonar.scanner.scan.ProjectReactorBuilder.cleanAndCheckModuleProperties(ProjectReactorBuilder.java:368)
at org.sonar.scanner.scan.ProjectReactorBuilder.cleanAndCheckProjectDefinitions(ProjectReactorBuilder.java:334)
at org.sonar.scanner.scan.ProjectReactorBuilder.execute(ProjectReactorBuilder.java:126)
at org.sonar.scanner.scan.MutableProjectReactorProvider.provide(MutableProjectReactorProvider.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.picocontainer.injectors.MethodInjector.invokeMethod(MethodInjector.java:129)
at org.picocontainer.injectors.MethodInjector.access$000(MethodInjector.java:39)
at org.picocontainer.injectors.MethodInjector$2.run(MethodInjector.java:113)
at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.picocontainer.injectors.MethodInjector.decorateComponentInstance(MethodInjector.java:120)
at org.picocontainer.injectors.CompositeInjector.decorateComponentInstance(CompositeInjector.java:58)
at org.picocontainer.injectors.Reinjector.reinject(Reinjector.java:142)
at org.picocontainer.injectors.ProviderAdapter.getComponentInstance(ProviderAdapter.java:96)
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:69)
... 37 more
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
C:\Users\remy.fischer\Desktop\NetBeansProjects\NetBeansProjects\BinPacking\sonar-scanner-3.0.3.778-windows\bin>
我不知道该怎么做,我尝试了很多我在这里看到的东西,但不幸的是没有任何效果..
【问题讨论】:
堆栈可能是错误的论坛,对我来说似乎是一个错误。它至少在说明问题所在方面存在错误。虽然我看不到您可以在哪里报告问题。您能否在某处添加版本 6.4 并尝试使用以前的版本。我正在经历同样的问题 我目前也遇到了同样的问题。你们中的任何人都设法弄清楚了吗? 【参考方案1】:我也有这个,但我使用 gradle 为 sonarcloud.io 运行声纳,一旦我打开 --stacktrace
和 --debug
,从日志中可以清楚地看到我收到了这个错误,因为我的凭据没有得到声纳服务器的识别。我仔细检查了它们,更改为正确的凭据后一切正常。
因此,除了按照建议使用-X
运行它以获取更多信息外,我建议您还尝试仔细检查您的凭据。
【讨论】:
【参考方案2】:在尝试从 Jenkins 内部触发声纳分析时,我遇到了同样的错误,经过数小时的搜索,我发现问题与路径定义有关。
在您的 sonar-project.properties 文件或项目配置部分的 SonarQube 配置部分中,确保属性 sonar.sources 使用正斜杠 (/) 定义路径
属性必须像这样定义: sonar.sources=D:/software/jenkins/JenkinsHome/workspace/test_jenkins
而不是这样: sonar.sources=D:\software\jenkins\JenkinsHome\workspace\test_jenkins
【讨论】:
谢谢,就是这样。【参考方案3】:我在尝试在 Github 上为 Sonarqube 配置拉取请求检查时遇到了同样的问题。在我的情况下,凭证是正确的,但我给
sonar.github.repository=myorg:myrepository
,它导致了这个错误。我通过将其更改为 sonar.github.repository=myorg/myrepository
来修复它
也许它可以帮助某人......
【讨论】:
【参考方案4】:这可能是由于项目目录的所有者和sonar-scanner的所有者不同,请尝试将755授予项目目录,以便sonar-scanner可以访问此
【讨论】:
【参考方案5】:对我们来说,问题是接口意外在文件名中的 I 上方有一顶帽子,文件名为 ÎFoo
【讨论】:
【参考方案6】:解决此问题的最佳方法是使用 --stacktrace 运行。这将提供完整的日志,您可以轻松识别问题。就我而言,这个问题是因为模块没有正确定义。
【讨论】:
【参考方案7】:我也遇到了这个问题,但我可以通过删除从市场下载的外部 SonarQube 插件来解决。不知道能不能解决你的问题,希望对你有帮助。
【讨论】:
【参考方案8】:我有同样的问题。如果您在 Docker 中运行 SonaeQube,请尝试删除与 SonarQube docker volume rm <some SonarQube volume>
绑定的卷。如果您在 docker 中仅使用 SonarQube 并且其他图像不重要或不存在,您可以使用(警告:该命令删除您机器上的所有卷)@ 987654322@。您也可以在创建 docker 容器时使用标志 --remove-orphans
,例如:docker-compose up -d --remove-orphans
。这个标签就像文档一样:
删除未在 Compose 文件中定义的服务的容器。
如果您在未清除卷的情况下切换 SonarQube 版本,可能会出现此问题
【讨论】:
【参考方案9】:如果这对任何人都有帮助,请创建 <sonar-scanner-dir>/conf/sonar-scanner.properties
文件为我修复它。
它实际上一开始就可以工作,但是当将它全部移到 docker 映像时就坏了 - 我忘记将 <sonar-scanner-dir>/conf/sonar-scanner.properties
文件移入。
在此处查看第六条帖子:You must define the following mandatory properties for 'Unknown': sonar.projectKey - Get help / SonarQube - SonarSource Community
顺便说一句:我收到的错误消息还包含以下内容,但 OP 的帖子中没有:
错误:您必须为 ‘未知’:sonar.projectKey
【讨论】:
以上是关于如何解决声纳错误:无法加载组件类 org.sonar.scanner.scan.ProjectLock的主要内容,如果未能解决你的问题,请参考以下文章
声纳图集成 - 无法加载自定义指标文件 SonargraphMetrics.properties