Reputation: 570
I have created a Jenkins project to run SonarQube analysis of my product code. The workspace contains multiple modules (some in Nodejs i.e. Javascript) and some in Java. My sonar properties looks like
sonar.projectKey=product-key
sonar.projectName=product-name
sonar.projectVersion=1.0
sonar.sources=./nodejsmodule1,./nodejsmodule2
sonar.sourceEncoding=UTF-8
This works perfectly without issue and gives me a nice SonarQube dashboard. However, if I change the sonar.sources
property to:
sonar.sources=./nodejsmodule1,./nodejsmodule2,./java-module-name/src/main/java
the Jenkins build fails with the following error:
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.api.resources.Project.getPom()Lorg/apache/maven/project/MavenProject;
at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectoryFromPluginConfiguration(SurefireUtils.java:56)
at org.sonar.plugins.surefire.api.SurefireUtils.getReportsDirectory(SurefireUtils.java:39)
at org.sonar.plugins.surefire.SurefireSensor.analyse(SurefireSensor.java:63)
at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:58)
at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:50)
at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:98)
at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85)
at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:258)
at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:253)
at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:243)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:100)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:85)
at org.sonar.batch.bootstrap.GlobalContainer.executeAnalysis(GlobalContainer.java:153)
at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:110)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:76)
at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
... 9 more
When I use
sonar.sources=./nodejsmodule1,./nodejsmodule2,./java-module-name/pom.xml
The error goes away. The multi-language analysis happens. The events widget on the SonarQube dashboard for the project shows that Java and JavaScript profiles got used during the analysis. But the code analysis results don't contain anything about Java. JavaScript analysis results show up. Doesn't matter in which order I specify the sonar.sources
values (i.e. JavaScript followed by Java or Java followed by JavaScript). I looked at other StackOverflow questions (e.g. Sonar analysing Maven 3 and multi language project using JENKINS). Clearly, they are specifying the location of the classes file as well. Maybe the java code is getting compiled during the Jenkins build step for SonarQube analysis so they can point to the target/classes
location. When I try this (i.e. sonar.binaries=./java-module-name/target/classes
), the build fails.
Based on http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+Maven#AnalyzingwithSonarQubeScannerforMaven-AnalyzingaMulti-languageProject, I also tried sonar.sources=./java-module-name/src,./java-module-name/pom.xml
. But that brings back the exception. The exception also happens for sonar.sources=./java-module-name,./java-module-name/pom.xml
, sonar.sources=./java-module-name/src/main,./java-module-name/pom.xml
and sonar.sources=./java-module-name/src/main/java,./java-module-name/pom.xml
.
What am I doing wrong?
Upvotes: 2
Views: 1290
Reputation: 495
The error only shows up when you include Java sources? So maybe you are using some outdated plugins on your 5.2, which are triggered on Java analysis and use the no longer available getPom()
method.
org.sonar.api.resources.Project.getPom()
is no longer available in SQ 5.2.
The stacktrace points to surefire. Which version are you using?
Upvotes: 0