JaCoCo SonarQube incompatible version 1007 - sonarqube

I'm using SonarQube for code quality control and suddenly builds that would otherwise pass can't be analyzed and fails.
[INFO] [00:00:03.630] Analysing /mySuperProject/target/jacoco.exec ->
java.io.IOException: Incompatible version 1007
When I invoke maven build with debug switch, this cause is revealed
Caused by: java.io.IOException: Incompatible version 1007.
at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:134)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:107)
While inspecting jacoco ExecutionDataReader, I found that exception is thrown from
if (version != ExecutionDataWriter.FORMAT_VERSION) {
throw new IOException(format("Incompatible version %x.",Integer.valueOf(version)));
}
and from ExecutionDataWriter I've found out
/** File format version, will be incremented for each incompatible change. */
public static final char FORMAT_VERSION = 0x1007;
What is this incompatible change and why does it happen?
Any ideas how to fix this challenge?

As already mentioned, this is due to a break in JaCoCo maven plugin code.
You can (temporarily) specify the version in your jenkins maven command like:
clean org.jacoco:jacoco-maven-plugin:<version>:prepare-agent install
e.g.
clean org.jacoco:jacoco-maven-plugin:0.7.4.201502262128:prepare-agent install
This was the workaround that helped us. But like most people, I'm still waiting for the fix to come.

What I did was to specify the jacoco version in my maven project.
<jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
</plugin>
That fix my issue!

Most likely that's caused by latest jacoco-maven-plugin update. Everything was working on 0.7.4.201502262128 but today we switched to 0.7.5.201505241946 which resulted in this error.

Run:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install
mvn org.jacoco:jacoco-maven-plugin:prepare-agent clean install -Pcoverage-per-test
mvn sonar:sonar
This will re-generate .exec files created by older versions of jacoco.

Try to update the Java plugin in SonarQube Update Center, this works for me. I updated the Java plugin from version 2.4 to latest 3.13.1.
SonarQube Update Center -> Plugin Updates -> Java

As kdowbecki mentionned it, this error is most likely due to an update of jacoco-maven-plugin.
Your SonarQube is most likely now using the new version of Jacoco Maven Plugin (probably the new 0.7.5.201505241946) but is actually trying to read an old version of a jacoco.exec (in your case it might be reading a jacoco.exec generated by jacoco maven plugin version 0.7.4.201502262128) which results in an incompatibility thrown by JaCoCo.
To fix this problem, you should make sure all your SonarQube/Jenkins jobs generate a JaCoCo report each time and do not rely on an older version of jacoco.exec that might have been generated by a previous job.

For me this, when doing a mvn install
Error while creating report: Cannot read execution data version 0x1006. This version of JaCoCo uses execution data version 0x1007
meant I had done an archetype generate but the archetype accidentally included the target directory with old jacoco files in it (or it had been checked into git on accident). Doing a mvn clean first (and checking that in) cleared up the issue. Guess jacoco is reluctant to overwrite the jacoco.exec file with a new one when there are no unit tests to run or something like that, so the old file gets preserved and attempted to used for the jacoco report. FWIW...
In general it means a version mismatch of generator vs. reporter.

I changed pom.xml like
groupId=org.jacoco
artifactId=jacoco-maven-plugin
version=0.8.4-SNAPSHOT
it worked for me

Related

Sonar Maven plugin is failing because of a newer maven assembler plugin, how can I get the new plugin to pass properties correctly?

Had to update our maven assembler version to 1.1.8 from 1.1.6. It's the only change that happened and now Sonar Maven Plugin is throwing this exception:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar
(default) on project ReconCoverage: java.util.ArrayList cannot be cast to java.lang.String ->
Plugins:
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7</version>
<groupId>com.CORPNAME.raptor.build</groupId>
<artifactId>assembler-maven-plugin</artifactId>
<version>1.1.8</version>
I have been looking into this for about a week, upgrading to this assembler version is required. No other teams are experiencing this issue from the upgrade because they are using Sonar through jenkins. I'm using the maven plugin because our project has many modules, and it structures the coverage results to match it.
I have looked through sonar's code and it seems to be happening in sonar.batch.bootstrap.userproperties. I'm guessing this is happening when the sonar properties are being passed in, items like: sonar.language, sonar.java.coveragePlugin, sonar.host.url, etc. etc.
Example of Coverage Properties:
<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.host.url>http://corp.sonar.url/</sonar.host.url>
<sonar.jdbc.url>jdbc:oracle:thin:#sonardb.corp.com:0000:sonardb</sonar.jdbc.url>
<sonar.jdbc.username>username</sonar.jdbc.username>
<sonar.jdbc.password>password</sonar.jdbc.password>
<sonar.jdbc.driver>oracle.jdbc.driver.OracelDriver</sonar.jdbc.driver>
According to sonar's code, it normally takes properties through a Map. And it throws this exception when one of those strings is an array list. Is there anyway to configure my properties so that the new maven assembler will pass these values correctly?
We have implemented a workaround in version 3.1.1 to circumvent buggy plugins injecting non string properties:
https://jira.sonarsource.com/browse/MSONAR-145
To use it just update you pom.xml to use:
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
I finally found a workaround for this problem. I decided to not go the route of running Java 7 and then 8 to build the coverage report(check previous answers and comments). I'm sure that would work, but since none of our dev or CI machines had Java 8 environments set up, I tried a different route.
I was initially building the sonar report at the end of a mvn clean install through a module CoverageModule(which as the last module to build). The 1.1.8 java assembler version was throwing a fit when it built the project, and then ran the analysis.
I kept the module so that during a normal build, it would still run my ant task plugin to merge all of our module's Jacoco reports. I removed the sonar-maven-plugin from that module's pom and put it in the Project's aggregator module(parent of all modules). After running a full mvn clean install, I can run a mvn sonar:sonar and there appears to be no conflict with the new assembler version, and the old sonar version I was using.

Specifying version of Sonar plugin

I have a Maven multi-module project and as part of my build I execute
mvn sonar:sonar
I get some unexpected behaviour with a particular maven plugin that there is no need to go into here and after a lot of debugging and trial-and-error, I decided to tweak the particular plugin in question to add some debugging. The plugin in question is the sonar javascript plugin (https://github.com/SonarSource/sonar-javascript).
I cloned the git repo, incremented the version to 2.16 (latest available is 2.15), modified a logging statement, executed mvn install. Then I went back to my project hoping that when I executed mvn sonar:sonar it would simply pick up the latest version of this plugin available on my local repo. It didn't. I tried adding this to my pom:
<plugin>
<groupId>org.sonarsource.javascript</groupId>
<artifactId>javascript</artifactId>
<version>2.16</version>
</plugin>
Still nothing. The logging statement is unchanged.
So how can I get the sonar execution to pick up my locally installed version of the plugin?
Just install the plugin on your SonarQube server.
Changing the plugin source means that you'll be on your own from their on though. If you've got legitimate issues/feedback with the JavaScript Plugin, then reach out to their maintainers on the SonarQube Google group. Constructive feedback will be heard, you'll get a chance to contribute directly to the sonar-javascript project, and the community we'll be able to benefit from your improvement(s) (rather than you flying solo with custom changes).

Maven Site / Project Info Reports Plugins Produce Empty Dependency Report

A dependencies report generated using the maven-project-info-reports-plugin is erroneously reporting only one project and zero transitive dependencies. However, a dependency-convergence report produces a complete list of dependencies. When running the project-info-reports:dependencies goal from the command line, either no output is being generated or the outputDirectory parameter is not working correctly (no report file is generated in the specified outputDirectory). Is there a default directory? I have only been able to produce the report with the mvn site plugin.
The only noticeable error I am getting is a series of "Artifact: XXXX has no file" errors, as reported in MPIR-251, but I'm wondering if this is a red herring and not indicative of the cause of the problem. Thoughts?
Configuration:
maven: 3.0.3
maven-site-plugin:3.1
maven-project-info-reports-plugin: 2.6
OS: Mac OS-X
As mentions at the usage page as
Maven has been configured to create the project info reports by default. There's no need to configure anything in your pom.xml to generate the project information reports.
Simply running
mvn site
If you would not to execute the site, please copy the maven-project-info-reports-plugin to the build. Please see the detail at my answer here. You may able to execute
mvn project-info-reports:dependencies
and you may see the result as your expected.
I hope this may help.
Regards,
Charlee Ch.

Sonar not picking up clover test results created by running maven in jenkins

I've been working on this all day and haven't been able to find a solution, so thought i'd turn to the stackoverflow community.
I have a server setup with Jenkins (version 1.454). It's configured to perform the build with Maven (version 3.0.4). The build command is as follows:
clean clover2:setup verify clover2:aggregate clover2:clover
Jenkins has the sonar plugin installed and configured. My sonar install (version 3) is on a different server to jenkins. After the build is completed, i can see the results on sonar (the basics of the build).
I have installed to sonar the clover plugin (sonar-clover-plugin-2.8.jar) manually by putting it into the 'extentions/plugins' folder. It appeared in sonar and I can configure it. I put in the license, version (3.1.4) and sonar.clover.reportPath as "target\site\clover\clover.xml".
When I run the build, it is successful as before, and I can see the basic results as before in Sonar, however, I cannot see any test code coverage results.
When I look at the maven build output I notice the following:
[INFO] Writing report to '/opt/jenkins/jobs/foo/workspace/target/site/clover/clover.xml'
and then near the bottom of the output:
[INFO] [15:08:36.586] Clover XML report not found
The following are also in my pom:
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.clover.reportPath>target\site\clover\clover.xml</sonar.clover.reportPath>
<sonar.surefire.reportsPath>target\surefire-reports</sonar.surefire.reportsPath>
<sonar.core.codeCoveragePlugin>clover</sonar.core.codeCoveragePlugin>
<sonar.clover.version>${clover.version}</sonar.clover.version>
When I look on the jenkins box, I can see that it has generated the clover.xml file (infact in my fiddling I have the clover plugin working on jenkins, so i can see the results there!).
I'm guessing at this stage that there is some issue with jenkins and sonar being on seperate boxes.
Any help would be appreciated!
Cheers.
After a lot more fiddling around, it appeared that I needed to change the following:
<sonar.clover.reportPath>${project.build.directory}/site/clover/clover.xml</sonar.clover.reportPath>
<sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
A good reference was the following:
all about pom variables

mvn sonar:sonar throws exception while doing Java AST scan

Please note :- My mvn clean install goes successful
but when i do mvn sonar:sonar it throws me
[ERROR] Squid Error occurs when analysing :/junk/test/src/main/java/API/com/API/HelloAPI.java
org.sonar.squid.api.AnalysisException: The source directory does not correspond to the package declaration com.API
at org.sonar.java.ast.visitor.PackageVisitor.checkPhysicalDirectory(PackageVisitor.java:93) [sonar-squid-java-plugin-2.8.jar:na]
at org.sonar.java.ast.visitor.PackageVisitor.createSourcePackage(PackageVisitor.java:75) [sonar-squid-java-plugin-2.8.jar:na]
http://sonar-dev.787459.n3.nabble.com/file/n3324837/squid-test.zip
The message is quite clear: the package declaration is wrong. It should be API.com.API if the source directory is /junk/test/src/main/java (that is the default value in Maven). An alternative is to change the source dir to src/main/java/API.
Could it be that your POM contains this line:
<sourceDirectory>.</sourceDirectory>
If so, changing it to this might help:
<sourceDirectory>src/main/java</sourceDirectory>
Maven doesn't care, but sonar does.
I had the same problem with sonar and a maven project generated by eclipse.
(Found the solution at http://www.digipedia.pl/usenet/thread/13899/13064/ )
I got the same error message after upgrading to a more recent sonar plugin (sonar-maven3-plugin:3.7.1/3.7.3/4.0 running against SonarQube Server 3.5.1) for a source file which worked with 3.6-RC3/3.6.3/3.7.0. Apparently 3.7.1 introduced the issue :-/

Resources