无法在SonarQube中执行java-custom-rules插件

时间:2014-11-06 09:16:45

标签: java sonarqube

我是SonarQube的新手,我正在为SOnarQube创建一个新的Metrics。 作为学习的一部分我正在尝试SonarQube网站中的示例。 我正在尝试here

给出的示例

我在eclipse中使用了maven clean和maven build并创建了jar文件。我将jar文件放在"扩展/插件" SonarQube服务器中的目录(我在Win 7机器上本地安装了服务器)。

然后我使用SonarQube Runner将我的项目与SonarQube链接。如何得到这个错误:

C:\xxx\Desktop\Workspace\sonar-test>sonar-runner  -e
C:\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.6.0_21 Sun Microsystems Inc. (32-bit)
Windows 7 6.1 x86
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: C:\sonar-runner-2.4\conf\sonar-runner.propertie
s
INFO: Project configuration file: C:\xxx\Desktop\Workspace\sona
r-test\sonar-project.properties
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: C:\xxx\Desktop\Workspace\sonar-test\.\.so
nar
INFO: SonarQube Server 4.5.1
13:47:39.244 INFO  - Load global referentials...
13:47:39.546 INFO  - Load global referentials done: 308 ms
13:47:39.570 INFO  - User cache: C:\xxx\.sonar\cache
13:47:39.597 INFO  - Install plugins
13:47:39.994 INFO  - Install JDBC driver
13:47:40.012 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
13:47:42.259 INFO  - Initializing Hibernate
13:47:45.201 INFO  - Load project referentials...
13:47:45.894 INFO  - Load project referentials done: 693 ms
13:47:45.896 INFO  - Load project settings
13:47:47.144 INFO  - Loading technical debt model...
13:47:47.195 INFO  - Loading technical debt model done: 51 ms
13:47:47.208 INFO  - Apply project exclusions
13:47:47.920 INFO  - -------------  Scan sonar-test
13:47:47.947 INFO  - Load module settings
13:47:49.148 INFO  - Loading rules...
13:47:50.030 INFO  - Loading rules done: 882 ms
13:47:50.106 INFO  - Configure Maven plugins
13:47:50.327 INFO  - Compare to previous analysis (2014-11-06)
13:47:50.352 INFO  - Compare over 30 days (2014-10-07, analysis of 2014-11-06 12
:28:06.816)
13:47:50.356 INFO  - No quality gate is configured.
13:47:50.840 INFO  - Base dir: C:\xxx\Desktop\Workspace\sonar-t
est\.
13:47:50.841 INFO  - Working dir: C:\xxx\Desktop\Workspace\sona
r-test\.\.sonar
13:47:50.846 INFO  - Source paths: src
13:47:50.847 INFO  - Source encoding: UTF-8, default locale: en_US
13:47:50.849 INFO  - Index files
13:47:51.001 INFO  - 2 files indexed
13:47:51.146 INFO  - Quality profile for java: Sonar way
13:47:51.171 INFO  - Sensor JavaSquidSensor...
13:47:51.363 INFO  - Java Main Files AST scan...
13:47:51.377 INFO  - 2 source files to be analyzed
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 13.831s
Final Memory: 8M/99M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:91)
        at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
        at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
        at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102
)
        at org.sonar.runner.api.Runner.execute(Runner.java:100)
        at org.sonar.runner.Main.executeTask(Main.java:70)
        at org.sonar.runner.Main.execute(Main.java:59)
        at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.NoSuchMethodError: org.sonar.plugins.java.api.tree.Tree.is(
[Lorg/sonar/plugins/java/api/tree/Tree$Kind;)Z
        at org.sonar.samples.java.ExampleCheck.visitMethod(ExampleCheck.java:69)

        at org.sonar.java.model.declaration.MethodTreeImpl.accept(MethodTreeImpl
.java:118)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.
java:41)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.
java:35)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitClass(BaseTreeVi
sitor.java:64)
        at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.j
ava:107)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.
java:41)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.
java:35)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(
BaseTreeVisitor.java:50)
        at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree
.java:120)
        at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.
java:41)
        at org.sonar.samples.java.ExampleCheck.scanFile(ExampleCheck.java:51)
        at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:91)

        at com.sonar.sslr.impl.ast.AstWalker.walkAndVisit(AstWalker.java:67)
        at org.sonar.java.ast.AstScanner.simpleScan(AstScanner.java:118)
        at org.sonar.java.ast.AstScanner.scan(AstScanner.java:83)
        at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:135)
        at org.sonar.java.JavaSquid.scan(JavaSquid.java:128)
        at org.sonar.plugins.java.JavaSquidSensor.analyse(JavaSquidSensor.java:8
6)
        at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.
java:79)
        at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:7
0)
        at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:119)
        at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanConta
iner.java:194)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.j
ava:233)
        at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScan
Container.java:228)
        at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanCon
tainer.java:221)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:64)
        at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:51)
        at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.ja
va:125)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentCo
ntainer.java:92)
        at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.
java:77)
        at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapCon
tainer.java:173)
        at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
        at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java
:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher
.java:87)
        ... 9 more
ERROR:
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

根据这个例子,每当遇到以字母“Z' Z'”开头的方法和注释时,这必须产生问题。

我尝试使用这样的输入创建一个类:

sample.java

package test;

public class Sample {

    public static void main(String[] args) {

        System.out.println("Test");
    }

    @Ztest(val="hi")
    public static void add()
    {
        System.out.println("Add Method");
    }
}

我还创建了一个注释文件:

Ztest.java

package test;

public @interface Ztest {
String val();
}

但是当我使用SonarQube Runner执行上述错误时。

请帮助我。

1 个答案:

答案 0 :(得分:1)

NoSuchMethodError意味着类加载器找到了一个类,但缺少该方法。当您在运行时使用较旧版本或较新版本的库时,会发生这种情况,而不是编译规则。如果你的类路径上有同一个库的多个版本,这仍然会发生,因为类加载器只会加载一次类,我不确定是否可以告诉它将使用哪个版本。

如果你看一下java-custom-rule的依赖关系,它取决于sonar-java-plugin version 2.5 ,请检查你的sonarqube实例是否有相同版本的插件。

编辑tl; dr更新你的sonarqube java插件