简体   繁体   中英

Not able to execute java-custom-rules plugin in SonarQube

I am a newbie to SonarQube and I am working on creating a new Metrics for SOnarQube. As a part of learning am trying the examples in the SonarQube site. I was trying the example given here

I used maven clean and maven build in eclipse and created the jar file. I placed the jar file in the "extension/plugins" directory in the SonarQube server (I have locally installed the server in my Win 7 machine).

Then I used SonarQube Runner to link my project with SonarQube. How ever am getting this error:

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.

According to this example this must create a issue whenever it encounters a method and a annotation starting with a letter 'Z'.

I tried creating a class with such inputs:

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");
    }
}

I also created an annotation file:

Ztest.java

package test;

public @interface Ztest {
String val();
}

But when I execute with the SonarQube Runner am getting the above error.

Kindly help me with this.

NoSuchMethodError means that a class is found by the classloader, but the method is missing. This occurs when you are using an older or newer version of a library at runtime, than your rule was compiled with. If you have multiple versions of the same library on your classpath, this still can occur, since the classloader will only load the class once, and I'm not sure if one can tell which version it will use.

If you look at the dependencies of java-custom-rule, it depends on sonar-java-plugin version 2.5 , please check if your sonarqube instance has the same version of this plugin.

EDIT tl;dr update your sonarqube java plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM