Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.sonar.api.utils.SonarException: Can not add twice the same measure on org.sonar.api.resources.File

I have a Jenkins Job that runs SonarRunner on a Maven project composed of several modules. The build fails when I configure SonarRunner to import Cobertura coverage reports.

SonarQube Runner 2.4
Java 1.7.0_55 Oracle Corporation (64-bit)
Windows 7 6.1 amd64
INFO: Error stacktraces are turned on.
INFO: Runner configuration file: C:\Jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\Sonar_Runner\conf\sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Work directory: C:\Jenkins\workspace\Sprint3\Application\.sonar
INFO: SonarQube Server 4.3
11:07:44.407 INFO  - Load batch settings
11:07:44.609 INFO  - User cache: C:\.sonar\cache
11:07:44.625 INFO  - Install plugins
11:07:44.765 INFO  - Install JDBC driver
11:07:44.781 WARN  - H2 database should be used for evaluation purpose only
11:07:44.781 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
11:07:45.951 INFO  - Initializing Hibernate
11:07:47.885 INFO  - Load project settings
11:07:47.963 INFO  - Apply project exclusions
11:07:48.229 INFO  - -------------  Scan JmsUtils
11:07:48.229 INFO  - Load module settings
11:07:49.508 INFO  - Loading technical debt model...
11:07:49.523 INFO  - Loading technical debt model done: 15 ms
11:07:49.523 INFO  - Loading rules...
11:07:49.789 INFO  - Loading rules done: 266 ms
11:07:49.804 INFO  - Configure Maven plugins
11:07:49.976 INFO  - Compare to previous analysis (2014-05-21)
11:07:50.007 INFO  - Compare over 30 days (2014-04-21, analysis of 2014-05-08 15:55:35.699)
11:07:50.007 INFO  - No quality gate is configured.
11:07:50.147 INFO  - Base dir: C:\Jenkins\workspace\Sprint3\Application\JmsUtils
11:07:50.147 INFO  - Working dir: C:\Jenkins\workspace\Sprint3\Application\.sonar\WSM_Application_JmsUtils
11:07:50.147 INFO  - Source dirs: C:\Jenkins\workspace\Sprint3\Application\JmsUtils\src\main\java
11:07:50.147 INFO  - Test dirs: C:\Jenkins\workspace\Sprint3\Application\JmsUtils\src\test\java
11:07:50.147 INFO  - Binary dirs: C:\Jenkins\workspace\Sprint3\Application\JmsUtils\target\classes
11:07:50.147 INFO  - Source encoding: windows-1252, default locale: en_US
11:07:50.147 INFO  - Index files
11:07:50.350 INFO  - 4 files indexed
11:07:50.428 INFO  - Quality profile for java: WSM way with Findbugs - Server Code
11:07:50.444 INFO  - Sensor JavaSquidSensor...
11:07:50.491 INFO  - Java Main Files AST scan...
11:07:50.506 INFO  - 2 source files to be analyzed
11:07:50.740 INFO  - 2/2 source files analyzed
11:07:50.756 INFO  - Java Main Files AST scan done: 265 ms
11:07:50.756 INFO  - Java bytecode scan...
11:07:50.787 WARN  - Class 'javax/jms/Session' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Connection' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Session' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/MessageProducer' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Message' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/ConnectionFactory' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Connection' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Session' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Session' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/Session' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'mil/navy/aif/domain/AuditRecord' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'javax/jms/JMSException' is not accessible through the ClassLoader.
11:07:50.787 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.803 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
11:07:50.803 INFO  - Java bytecode scan done: 47 ms
11:07:50.803 INFO  - Java Test Files AST scan...
11:07:50.803 INFO  - 2 source files to be analyzed
11:07:50.849 INFO  - Java Test Files AST scan done: 46 ms
11:07:50.849 INFO  - 2/2 source files analyzed
11:07:50.849 INFO  - Package design analysis...
11:07:50.865 INFO  - Package design analysis done: 16 ms
11:07:50.881 INFO  - Sensor JavaSquidSensor done: 437 ms
11:07:50.881 INFO  - Sensor QProfileSensor...
11:07:50.881 INFO  - Sensor QProfileSensor done: 0 ms
11:07:50.881 INFO  - Sensor FindbugsSensor...
11:07:50.896 INFO  - Execute Findbugs 2.0.3...
11:07:52.269 INFO  - Findbugs output report: C:\Jenkins\workspace\Sprint3\Application\.sonar\WSM_Application_JmsUtils\findbugs-result.xml
The following classes needed for analysis were missing:
  javax.jms.Session
  javax.jms.Connection
  org.apache.log4j.Logger
  javax.jms.ConnectionFactory
  javax.jms.Message
  javax.jms.MessageProducer
  mil.navy.aif.domain.AuditRecord
  javax.jms.JMSException
  javax.jms.Topic
  javax.jms.Destination
11:07:54.609 INFO  - Execute Findbugs 2.0.3 done: 3698 ms
11:07:54.609 INFO  - Sensor FindbugsSensor done: 3728 ms
11:07:54.609 INFO  - Sensor JaCoCoItSensor...
11:07:54.609 INFO  - Project coverage is set to 0% as no JaCoCo execution data has been dumped: C:\Jenkins\workspace\Sprint3\Application\JmsUtils\target\jacoco-it.exec
11:07:54.672 INFO  - Sensor JaCoCoItSensor done: 63 ms
11:07:54.672 INFO  - Sensor JaCoCoOverallSensor...
11:07:54.672 INFO  - Sensor JaCoCoOverallSensor done: 0 ms
11:07:54.672 INFO  - Sensor CoberturaSensor...
11:07:54.687 INFO  - parsing C:\Jenkins\workspace\Sprint3\Application\JmsUtils\target\site\cobertura\coverage.xml
11:07:54.765 INFO  - Sensor CoberturaSensor done: 93 ms
11:07:54.765 INFO  - Sensor CpdSensor...
11:07:54.765 INFO  - SonarEngine is used for java
11:07:54.765 INFO  - Cross-project analysis disabled
11:07:54.812 INFO  - Sensor CpdSensor done: 47 ms
11:07:54.812 INFO  - Sensor InitialOpenIssuesSensor...
11:07:54.890 INFO  - Sensor InitialOpenIssuesSensor done: 78 ms
11:07:54.890 INFO  - Sensor ProfileEventsSensor...
11:07:54.906 INFO  - Sensor ProfileEventsSensor done: 16 ms
11:07:54.906 INFO  - Sensor ProjectLinksSensor...
11:07:54.906 INFO  - Sensor ProjectLinksSensor done: 0 ms
11:07:54.906 INFO  - Sensor VersionEventsSensor...
11:07:54.921 INFO  - Sensor VersionEventsSensor done: 15 ms
11:07:54.921 INFO  - Sensor FileHashSensor...
11:07:54.921 INFO  - Sensor FileHashSensor done: 0 ms
11:07:54.921 INFO  - Sensor SurefireSensor...
11:07:54.921 INFO  - parsing C:\Jenkins\workspace\Sprint3\Application\JmsUtils\target\surefire-reports
11:07:54.937 INFO  - Sensor SurefireSensor done: 16 ms
11:07:54.937 INFO  - Sensor JaCoCoSensor...
11:07:54.937 INFO  - Project coverage is set to 0% as no JaCoCo execution data has been dumped: C:\Jenkins\workspace\Sprint3\Application\JmsUtils\target\jacoco.exec
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 11.513s
Final Memory: 21M/674M
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: org.sonar.api.utils.SonarException: Can not add twice the same measure on org.sonar.api.resources.File@318c8090[key=src/main/java/mil/navy/wsm/jmsutils/Auditor.java,deprecatedKey=mil.navy.wsm.jmsutils.Auditor,path=src/main/java/mil/navy/wsm/jmsutils/Auditor.java,dir=mil/navy/wsm/jmsutils,filename=Auditor.java,language=Java]: org.sonar.api.measures.Measure@7f4c8759[id=<null>,metricKey=lines_to_cover,metric=Metric[id=38,formula=<null>,key=lines_to_cover,description=Lines to cover,type=INT,direction=1,domain=Tests,name=Lines to cover,qualitative=false,userManaged=false,enabled=true,origin=JAV,worstValue=<null>,bestValue=<null>,optimizedBestValue=false,hidden=false,deleteHistoricalData=false],value=28.0,data=<null>,description=<null>,alertStatus=<null>,alertText=<null>,tendency=<null>,date=<null>,variation1=<null>,variation2=<null>,variation3=<null>,variation4=<null>,variation5=<null>,url=<null>,characteristic=<null>,requirement=<null>,personId=<null>,persistenceMode=FULL]
    at org.sonar.batch.index.Bucket.addMeasure(Bucket.java:95)
    at org.sonar.batch.index.DefaultIndex.addMeasure(DefaultIndex.java:209)
    at org.sonar.batch.DefaultSensorContext.saveMeasure(DefaultSensorContext.java:168)
    at org.sonar.plugins.jacoco.JaCoCoSensor$UnitTestsAnalyzer.saveMeasures(JaCoCoSensor.java:86)
    at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:151)
    at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:107)
    at org.sonar.plugins.jacoco.JaCoCoSensor.analyse(JaCoCoSensor.java:61)
    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:131)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:178)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:199)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:194)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:192)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:187)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:56)
    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:44)
    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:82)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:175)
    at org.sonar.batch.bootstrap.BootstrapContainer.doAfterStart(BootstrapContainer.java:163)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
    at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:92)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:74)
    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
ERROR: 
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
Build step 'Invoke Standalone Sonar Analysis' marked build as failure
Finished: FAILURE

Here are the project properties that I've configured in Jenkins for the SonarRunner analysis:

sonar.projectKey=WSM:Application
sonar.projectName=Application
sonar.projectVersion=1.0.2.4-SNAPSHOT
sonar.sources=src/main/java
sonar.binaries=target/classes
sonar.tests=src/test/java
sonar.junit.reportsPath=target/surefire-reports
sonar.java.coveragePlugin=cobertura
sonar.cobertura.reportPath=target/site/cobertura/coverage.xml
sonar.modules=JmsUtils,MsgGenerationUtils,WsmCopyAsNew,WsmGeomCreator,WsmGoldMsgParser,WsmJpa,WsmMsgGenerator

If I remove the sonar.java.coveragePlugin and the sonar.cobertura.reportPath properties, the build succeeds, however I will not have any coverage metrics.

I believe the issue is occurring because there is a conflict with Cobertura and JaCoCo trying to both measure the same files. You can see in the stack trace that the JaCoCo sensor is involved in the error. I do not wish to use JaCoCo at all.

Jenkins version: 1.560
Jenkins Sonar Plugin version: 2.1
Sonar version: 4.3
Sonar Cobertura Plugin version: 1.6.1
Sonar Java Plugin version: 2.2

like image 223
jewbix.cube Avatar asked Sep 30 '22 18:09

jewbix.cube


2 Answers

A workaround with version 2.2. ist to set

sonar.jacoco.reportMissing.force.zero=False

in sonar-project.properties.

like image 126
binford Avatar answered Oct 11 '22 07:10

binford


Please use the Java plugin version 2.2.1 that was released to fix this very issue.

In version 2.2 if no report is present JaCoCo sets coverage to 0 which provoke the issue you face. Whereas in 2.2.1 if no report is present, coverage is not set.

like image 20
benzonico Avatar answered Oct 11 '22 06:10

benzonico