gpt4 book ai didi

Sonar Qube - "The class ' .. .' could not be matched to its original source file."

转载 作者:行者123 更新时间:2023-12-02 23:17:16 26 4
gpt4 key购买 nike

在我的 SonarQube 分析中,我可以发现以下错误:

WARN: The class 'com.mycompany.bla.BlaTest' could not be matched to its original source file. It might be a dynamically generated class.
WARN: Failed to load the class file metadata
org.sonar.plugins.findbugs.resource.ClassMetadataLoadingException: ASM failed to load classfile metadata
at org.sonar.plugins.findbugs.resource.DebugExtensionExtractor.getDebugExtFromClass(DebugExtensionExtractor.java:49)
at org.sonar.plugins.findbugs.resource.ByteCodeResourceLocator.extractSmapLocation(ByteCodeResourceLocator.java:166)
at org.sonar.plugins.findbugs.FindbugsSensor.execute(FindbugsSensor.java:171)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:180)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:302)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:297)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:295)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:271)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
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.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:171)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalArgumentException: null
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:160)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:143)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:418)
at org.sonar.plugins.findbugs.resource.DebugExtensionExtractor.getDebugExtFromClass(DebugExtensionExtractor.java:43)
... 35 common frames omitted

我发现错误发生在源位于“testsrc/com/mycompany/...”下的单元测试文件上。编译后的测试类位于“classes”

所以项目结构是:

myProject
|- src
|- testsrc
|- classes

在我的 sonar-project.properties 中,我有以下配置:

sonar.tests=testsrc
sonar.sources=src

这里正确的解决方案是什么?排除 FindBugs 分析测试类或将 testsrc 文件夹添加到分析的源中?

最佳答案

技巧是向 sonarqube 添加 findbugsexclude.xml:

sonar.findbugs.excludesFilters=findbugsexclude.xml

并排除测试类中的所有测试类和内部类:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="~.*Test$"/>
</Match>
<Match>
<Class name="~.*Test\$.*$"/>
</Match>
</FindBugsFilter>

关于 Sonar Qube - "The class ' .. .' could not be matched to its original source file.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52180272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com